# Newb trying to figure out ActiveRecord relationships

**URL:** <https://www.ruby-forum.com/t/newb-trying-to-figure-out-activerecord-relationships/105539>\
**Category:** Rails\
**Created:** [May 30, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/newb-trying-to-figure-out-activerecord-relationships/105539 "2007-05-30T22:20:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tayknight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/da6949/32.png) [@tayknight](https://www.ruby-forum.com/u/tayknight)\
**Post date:** [May 30, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/newb-trying-to-figure-out-activerecord-relationships/105539/1 "2007-05-30T22:20:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tayknight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/da6949/32.png) [@tayknight](https://www.ruby-forum.com/u/tayknight)\
**Post date:** [May 30, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/newb-trying-to-figure-out-activerecord-relationships/105539/2 "2007-05-30T23:18:39Z")

</div>

## Item

belongs\_to :brand  
has\_one :commercial

## Brand

has\_many :items

## Commercial

belongs\_to :item

Michael

---

<div class="post-metadata">

**Author:** ![tayknight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/da6949/32.png) [@tayknight](https://www.ruby-forum.com/u/tayknight)\
**Post date:** [May 30, 2007, 11:39pm UTC](https://www.ruby-forum.com/t/newb-trying-to-figure-out-activerecord-relationships/105539/3 "2007-05-30T23:39:41Z")

</div>

Thanks, Michael. That worked perfectly. For some reason I had all the  
relationships exactly backwards.
