Hi, Apologies if this question has been answered before - I''ve looked through the list and couldn''t find anything answering my question. Suppose I have users and skills, and I want to link the two through two join models, one for skills a user has, another for skills a user wants to improve. I can get has_many :though working for one join model, but I don''t know how to get the other one working because you can''t use :class_name or :foreign_key - I looked at :source but that doesn''t seem to do what I need (but I could be wrong). Example class User # ... end class Skill # This one is fine has_many :skill_ratings has_many :users, :through => :ratings has_many :skill_requests # What do I add here to make requestees use the User model and user_id key? has_many :requestees, :through => :requests end class SkillRequest belongs_to :user belongs_to :skill end class SkillRating belongs_to :user belongs_to :skill end Any thoughts - or can you not do this with has_many :through and have to manually create the joins yourself? TIA, Roland --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
apologies that line should be: has_many :requestees, :through => :skill_requests On Dec 13, 4:58 pm, "Roland Swingler" <roland.swing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Apologies if this question has been answered before - I''ve looked > through the list and couldn''t find anything answering my question. > > Suppose I have users and skills, and I want to link the two through two > join models, one for skills a user has, another for skills a user wants > to improve. > > I can get has_many :though working for one join model, but I don''t know > how to get the other one working because you can''t use :class_name or > :foreign_key - I looked at :source but that doesn''t seem to do what I > need (but I could be wrong). > > Example > > class User > # ... > end > > class Skill > # This one is fine > has_many :skill_ratings > has_many :users, :through => :ratings > > has_many :skill_requests > # What do I add here to make requestees use the User model and > user_id key? > has_many :requestees, :through => :requests > end > > class SkillRequest > belongs_to :user > belongs_to :skill > end > > class SkillRating > belongs_to :user > belongs_to :skill > end > > Any thoughts - or can you not do this with has_many :through and have > to manually create the joins yourself? > > TIA, > Roland--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Apologies once again Apparently :source _is_ what is required to do this. I think the examples that I have seen have implied that the source must be something that you have already ":has_manyed". So the line is: has_many :requestees, :though => :skill_requests, :source => :user I''ll go and crawl into a small pit of shame for semi-spamming the list now :( Cheers, Roland On Dec 13, 5:00 pm, "Roland Swingler" <roland.swing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> apologies that line should be: > > has_many :requestees, :through => :skill_requests > > On Dec 13, 4:58 pm, "Roland Swingler" <roland.swing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Hi, > > > Apologies if this question has been answered before - I''ve looked > > through the list and couldn''t find anything answering my question. > > > Suppose I have users and skills, and I want to link the two through two > > join models, one for skills a user has, another for skills a user wants > > to improve. > > > I can get has_many :though working for one join model, but I don''t know > > how to get the other one working because you can''t use :class_name or > > :foreign_key - I looked at :source but that doesn''t seem to do what I > > need (but I could be wrong). > > > Example > > > class User > > # ... > > end > > > class Skill > > # This one is fine > > has_many :skill_ratings > > has_many :users, :through => :ratings > > > has_many :skill_requests > > # What do I add here to make requestees use the User model and > > user_id key? > > has_many :requestees, :through => :requests > > end > > > class SkillRequest > > belongs_to :user > > belongs_to :skill > > end > > > class SkillRating > > belongs_to :user > > belongs_to :skill > > end > > > Any thoughts - or can you not do this with has_many :through and have > > to manually create the joins yourself? > > > TIA, > > Roland--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---