# Problem calling has\_many's defined attributes on a specific

**URL:** <https://www.ruby-forum.com/t/problem-calling-has-manys-defined-attributes-on-a-specific/47946>\
**Category:** Rails\
**Created:** [November 15, 2005, 11:43am UTC](https://www.ruby-forum.com/t/problem-calling-has-manys-defined-attributes-on-a-specific/47946 "2005-11-15T11:43:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![agenteo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@agenteo](https://www.ruby-forum.com/u/agenteo)\
**Post date:** [November 15, 2005, 11:43am UTC](https://www.ruby-forum.com/t/problem-calling-has-manys-defined-attributes-on-a-specific/47946/1 "2005-11-15T11:43:55Z")

</div>

Hi,  
I’ve got two postgres tables:  
CREATE TABLE prodotti (it’s a products table)  
(  
id serial NOT NULL,  
descrizione varchar NOT NULL,  
client\_id int8 NOT NULL,  
CONSTRAINT prodotti\_pkey PRIMARY KEY (id)  
)  
WITHOUT OIDS;  
ALTER TABLE prodotti OWNER TO user;

CREATE TABLE prezzi\_prodotti (it’s a product’s prices table)  
(  
id serial NOT NULL,  
prezzo\_unitario numeric NOT NULL,  
annotazioni varchar,  
prodotti\_id int4 NOT NULL,  
CONSTRAINT prezzi\_prodotti\_pkey PRIMARY KEY (id),  
CONSTRAINT prezzi\_prodotti\_prodotti\_id\_fkey FOREIGN KEY  
(prodotti\_id) REFERENCES prodotti (id) ON UPDATE CASCADE ON DELETE  
CASCADE  
)  
WITHOUT OIDS;  
ALTER TABLE prezzi\_prodotti OWNER TO user;

mapped on: prezzi\_prodotti.rb  
1 class PrezziProdotti \< ActiveRecord::Base  
2 set\_table\_name “prezzi\_prodotti”  
3 belongs\_to :prodotti  
and on: prodotti.rb  
1 class Prodotti \< ActiveRecord::Base  
2 set\_table\_name “prodotti”  
3 has\_many :prezzi\_prodotti

when I try to retrieve the product prices from a searched product I get:  
irb(main):004:0\> p = Prodotti.find(1)  
=\> #\<Prodotti:0xb778fab8 @attributes={“client\_id”=\>“43”,  
“descrizione”=\>“product description”, “id”=\>“1”}\>  
irb(main):005:0\> p.prezzi\_prodotti  
NameError: uninitialized constant PrezziProdottus  
from  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active\_support/dependencies.rb:195:in  
`const_missing' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/association_proxy.rb:12:in`initialize’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active\_record/associations/has\_many\_association.rb:5:in  
`eval' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/association_proxy.rb:12:in`initialize’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active\_record/associations/has\_many\_association.rb:5:in  
`initialize' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations.rb:735:in`new’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active\_record/associations.rb:735:in  
`prezzi_prodotti' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations.rb:731:in`prezzi\_prodotti’  
from (irb):5

my guess is:  
NameError: uninitialized constant PrezziProdottus  
is the point, someway the name class is being messed up… like he  
mind to pluralize even if I’ve specified the set\_table\_name clause.  
I’ve never experienced something like this. Can someone help me?  
Thanks,  
Enrico

–  
“The only thing necessary for the triumph of evil  
is for good men to do nothing”  
Edmund Burke

---

<div class="post-metadata">

**Author:** ![agenteo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@agenteo](https://www.ruby-forum.com/u/agenteo)\
**Post date:** [November 15, 2005, 1:25pm UTC](https://www.ruby-forum.com/t/problem-calling-has-manys-defined-attributes-on-a-specific/47946/2 "2005-11-15T13:25:58Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Nov 15, 2005, at 2:41 AM, Enrico T. wrote:

> has\_many :prezzi\_prodotti

has\_many :prezzi\_prodotti, :class\_name =\> ‘PrezziProdotti’

Association names are assumed to be pluralized, so if you choose not  
to pluralize them you need to explicitly specify the corresponding  
class name.

jeremy  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDedOcAQHALep9HFYRApSBAJkBmQowdV/S+3yk46qVC2Rh7mSciQCg15Cm  
AJu2wqkrbmkTioVJQZt3yJc=  
=hW+r  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![agenteo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@agenteo](https://www.ruby-forum.com/u/agenteo)\
**Post date:** [November 15, 2005, 3:11pm UTC](https://www.ruby-forum.com/t/problem-calling-has-manys-defined-attributes-on-a-specific/47946/3 "2005-11-15T15:11:08Z")

</div>

> has\_many :prezzi\_prodotti, :class\_name =\> ‘PrezziProdotti’  
> thanks a lot, this has solved the problem

But it’s really weird I’ve never experienced that error on other  
classes loaded with set\_table\_name but without a class\_name.  
How could it be?

Thanks,  
Enrico

–  
“The only thing necessary for the triumph of evil  
is for good men to do nothing”  
Edmund Burke

---

<div class="post-metadata">

**Author:** ![agenteo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@agenteo](https://www.ruby-forum.com/u/agenteo)\
**Post date:** [November 15, 2005, 3:30pm UTC](https://www.ruby-forum.com/t/problem-calling-has-manys-defined-attributes-on-a-specific/47946/4 "2005-11-15T15:30:29Z")

</div>

On 11/15/05, Jeremy K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> class name.
> 
> jeremy

You can also turn off ActiveRecord::Base::pluralize\_table\_names.

–fabio
