Problem calling has_many's defined attributes on a specific

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:ininitialize’
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:ininitialize’
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:innew’
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:inprezzi_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

-----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-----

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

On 11/15/05, Jeremy K. [email protected] wrote:

class name.

jeremy

You can also turn off ActiveRecord::Base::pluralize_table_names.

–fabio