How to fetch a field through few tables

Hi, I have the following situation, 3 tables as follows:

TableA: TableB: TableC:


TableB_ID User_ID User_ID
User_Name

TableB_ID is a foreign key to TableB, User_ID in TableB and TableC is
foreign key to a table that play no role hier.

now I would like to display the User_Name field found in TableC in a e.g
index view. So I need to go from TableA with the TableB_ID foreign key
to get the User_ID field from TableB, then search for the record in
TableC that has this User_ID as one of its fields and get the User_Name.

This should look something like:

<%= TableA.TableB.TableC(where TableB.User_ID == TableC.User_ID).User_Name %>

I know that the syntax above is not correct but just to show what I’m
looking for.

Hope I made my self clear :wink:

Thanks
Dani

<%= course_attendee.sys_title.name unless course_attendee.sys_title.nil? %>

Do you have these set up as models in your application?

Perhaps you should take a look at the Rails Guides, specifically the
ones on
Models

On 14 September 2011 21:30, Tim S. [email protected] wrote:

Do you have these set up as models in your application?
Perhaps you should take a look at the Rails Guides, specifically the ones on
Models
Active Record Query Interface — Ruby on Rails Guides

It might even be better to start with the one on ActiveRecord
Associations

Colin


gplus.to/clanlaw