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.
tayknight (Guest)
on 2007-05-31 00: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.
MichaelLatta (Guest)
on 2007-05-31 01:18
(Received via mailing list)
Item
---------
belongs_to :brand
has_one :commercial

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

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


Michael
tayknight (Guest)
on 2007-05-31 01: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.