# Problem linking tables and accessing relationship heirarchy

**URL:** <https://www.ruby-forum.com/t/problem-linking-tables-and-accessing-relationship-heirarchy/145061>\
**Category:** Ruby\
**Created:** [August 5, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/problem-linking-tables-and-accessing-relationship-heirarchy/145061 "2008-08-05T17:51:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [August 5, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/problem-linking-tables-and-accessing-relationship-heirarchy/145061/1 "2008-08-05T17:51:16Z")

</div>

I’m not quite understanding this relationship thing between models and  
tables. What I am trying to do within my view is get the price  
information  
by referring to it like this:

\<%= @item.itemprice.Qty1 %\>

In each of my individual views for the item\_master table and the  
itemprice  
table I can get the info directly, but I can’t figure out how to access  
the  
price that corresponds to the item.

Here is my item.rhtml view test page:

* * *

Note: this works

\<%= @item.itemDescription %\>

This does not

\<%= @item.itemprice.Qty1 %\>

Below is all my Information:

My Models:

* * *

item\_master.rb

class ItemMaster \< ActiveRecord::Base  
has\_many :itemprices  
has\_many :item\_sub\_prices  
has\_many :item\_price\_specials  
end

* * *

itemprice.rb

class itemprice \< ActiveRecord::Base  
belongs\_to :item\_master  
end

My Controllers:

* * *

item\_master\_controller.rb

class ItemMasterController \< ApplicationController

def show\_all  
@items = ItemMaster.find(:all)  
end

def item  
@item = ItemMaster.find(params[:id])  
end  
end

* * *

itemprice\_controller.rb

class ItemPriceController \< ApplicationController  
def show  
@price = itemprice.find(params[:id])  
end  
end

* * *

Thanks,

Brian

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [August 5, 2008, 5:55pm UTC](https://www.ruby-forum.com/t/problem-linking-tables-and-accessing-relationship-heirarchy/145061/2 "2008-08-05T17:55:45Z")

</div>

try this in the rails forum
