On Monday, June 10, 2013 4:39:16 AM UTC-4, Ruby-Forum.com User
wrote:>
> Hello i have some errors in generating ERD from models.. I guess i have
> wrong associations.. please look at it
>
> [DB]
>
> orders
> ------
> payment_address_id
> delivery_address_id
> user_id
> products_orders
> ---------------
> product_id
> order_id
>
> [MODELS]
>
> Order
> -----
> has_many :products_orders
> has_many :products, :through => :products_orders
> belongs_to :address, :foreign_key => :payment_address_id
> belongs_to :address, :foreign_key => :delivery_address_id
> belongs_to :user
>
> products_orders
> ---------------
> belongs_to :product
> belongs_to :order
>
> [rake erd]
> Warning: Ignoring invalid association :products_orders on Order
> (uninitialized constant Order::ProductsOrder)
> Warning: Ignoring invalid association :products on Order (uninitialized
> constant Order::ProductsOrder)
> Warning: Ignoring invalid association :user on Order (uninitialized
> constant Order::User)
> Warning: Ignoring invalid association :products_orders on Product
> (uninitialized constant Product::ProductsOrder)
> Warning: Ignoring invalid association :orders on Product (uninitialized
> constant Product::ProductsOrder)
> what have i wrong ? Thank you
>
> --
> Posted via http://www.ruby-forum.com/.
>
You''ve deviated from the Rails conventions, which you can do, but then
you
have to tell ActiveRecord how to handle it. Rails expects model names to
have a singular form, and table names to be the plural of that name. For
example, if the table name is users, it expects a model named User. If
the model name is Product, it''s expecting the table name to be
Products.
In your case, you''ve set up products_orders (the plural) as both the
model
name and the table name. It''s seeing the table name products_orders,
which
conforms to its expectations, and is expecting a model name ProductsOrder
(the singular) which it can''t find.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/0c4df653-8c88-4eda-90ce-38b6175adde7%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.