Forum: Ruby on Rails newb trying to figure out ActiveRecord relationships

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ac25a42f3e336878aa9aca1b88118dbb?d=identicon&s=25 tayknight (Guest)
on 2007-05-30 22:20
(Received via mailing list)
3 tables. item, brand, commercial

item
--------
id
name
brand_id
name

brand
---------
id
name

commercial
----------
id
item_id

The idea is that a commercial will have one item.
each item will have brand.
and a brand may have zero to many items.

I can't figure out how to make the relationships for my models.
Eventually, i'd like to be able to show a brand name from a
commercial's view.
588ab1c0a5610a7e160a3b101abb91e6?d=identicon&s=25 MichaelLatta (Guest)
on 2007-05-30 23:18
(Received via mailing list)
Item
---------
belongs_to :brand
has_one :commercial

Brand
----------
has_many :items

Commercial
----------
belongs_to :item


Michael
Ac25a42f3e336878aa9aca1b88118dbb?d=identicon&s=25 tayknight (Guest)
on 2007-05-30 23:39
(Received via mailing list)
Thanks, Michael. That worked perfectly. For some reason I had all the
relationships exactly backwards.
This topic is locked and can not be replied to.