Rick wrote: > And thanks for the links by the way. > > But looking at the second link they show: > > class Customer < ActiveRecord::Base > has_many :orders, :dependent => :destroy > end > > class Order < ActiveRecord::Base > belongs_to :customer > end > > How is that any different than my association for Person and Address > (which you said was wrong)? > > class Person < ActiveRecord::Base > has_many :addresses, :dependent => :destroy > end > > class Address < ActiveRecord::Base > belongs_to :product > end > > It looks the same as it does in the doc, unless I'm missing something? > > On Fri, Jul 10, 2009 at 4:40 PM, Rick<[email protected]> wrote: >>> end >>> >>> end >> >>> But, you have class Address belonging to Product but your association >>> for Person is stating that addresses belong to it. �Which does address >>> really belong to? >> >> Well the reason I added Addresses 'belonging to" Product is so that it >> would put the FK product_id in the Address table. �I guess I should >> just leave off belongs_to :person on the Address model? >> > > > > -- > Rick R
Hi Rick, Thanks for looking at the links and thanks for the clarifications. I missed your Color class association so that part is fine. Looking at the Customer - Order association you placed here.. Customer --> Has Many --> Orders Orders --> Belongs to --> Customer That's a correct association... Now look at yours: Person --> Has Many --> Addresses Address --> Belongs to --> (PRODUCT)? Notice there's no correct association here... Anytime you you have a name_id in any of your tables, rails automatically knows it's a foreign key once you apply the association. Person has many addresses Address belongs to person Product has many addresses Address belongs to product That sound about right? Class Person has_many :addresses, :dependent => :destroy end Class Address belongs_to :person belongs_to :product end Class Product has_many :addresses end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

