Complicated relationship, not sure how to access

I have three Models - with relevant column/method and relationships

Position - company_id
belongs_to :user
belongs_to :cdetail

User- id
has_one :cdetail
has_many :positions

Cdetail - user_id , company_name
belongs_to :user
has_many :positions

I’m trying to access the company_name from Cdetail that is associated
with the company_id in Position (which is actually the user id in the
User model.
Maybe my naming conventions are wrong ? I’m not sure how to get it to
work.
Any ideas ?

TIA
Stuart

Well, I’m not exactly sure what you are trying to do, but it seems
that Position is a “Has And Belongs To Many” relationship, so maybe
use has_many :through? I’m sure this doesn’t really answer your
question, but I don’t really get the question.

-carl

has_one :cdetail
Any ideas ?

TIA
Stuart

On 9/23/06, Carl L. [email protected] wrote:

Well, I’m not exactly sure what you are trying to do, but it seems
that Position is a “Has And Belongs To Many” relationship, so maybe
use has_many :through? I’m sure this doesn’t really answer your
question, but I don’t really get the question.

-carl

I’ll hold off on rephrasing the question but I have been thinking of
HABTM
positions can have many users and cdetails
users and cdetails can have many positions
I think :slight_smile: Well I’ll own up to it since it’s my schema.

Essentially though the company_name is in the cdetails table and is
associated with the user id in the users table. positions column
company_id is the same as the user id. If that complicates it …i
mean makes it any clearer.

Stuart

Decide to re-phrase my question - though I’m reading through the model
relationship material again.

Again here are my three models / methods
Position - company_id
User- id
Cdetail - user_id , company_name

So the column company_id is the same as the id (in the User model).
When a user creates a Position their user id goes into the company_id
column.

In the Cdetail model, the user_id relates to the User model id column.
In addition though it has a column for the user to enter their
company name (company_name).

If this is any clearer, I’m trying to figure out the best way when
searchign through the Positon model , to take that company_id and spit
out the company_name.

Stuart