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 -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 On 9/23/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > -- > http://en.wikipedia.org/wiki/Dark_ambient > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> > On 9/23/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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 > > StuartOn 9/23/06, Carl Lerche <carl.lerche-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. > > -carlI''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 :) 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---