Okay folks, I''m feeling like a fool. I''m sure I''m not the first person to run into this, but I can''t find the necessary info. Basically I need to create two tables. The first to hold actual content. And the second to link pairs of content records. For example, a "persons" table and a "friends" table that pairs up two person records. Obviously, I can''t have two fields in the friends table named ''person_id''. So how do I assign a field as a foreign key, that isn''t named in the default format "table_id"? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
igotimac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-07 15:29 UTC
Re: non-"table_id" foreign key
your table friends: has left_person_id right_person_id so class Friend ... belongs_to :right_person, :class_name => ''Person'', :foreign_key => ''right_person_id'' belongs_to :left_person, :class_name => ''Person'', :foreign_key => ''left_person_id'' --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
check out this article and the comments to it, someone did exactly something like this... http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
will wrote:> Okay folks, I''m feeling like a fool. I''m sure I''m not the first person > to run into this, but I can''t find the necessary info. > > Basically I need to create two tables. The first to hold actual > content. And the second to link pairs of content records. For > example, a "persons" table and a "friends" table that pairs up two > person records. Obviously, I can''t have two fields in the friends > table named ''person_id''. So how do I assign a field as a foreign key, > that isn''t named in the default format "table_id"?You could also use a has_and_belongs_to_many association if your mapping table really just contains the 2 person ids. Like igotimac implied in his comment, you can name your foreign keys whatever you want, just reference them explicitly when you create your association using the options macros for the association (foreign_key=>, class_name=>, etc) Here is a reference to has_and_belongs_to_many: http://wiki.rubyonrails.org/rails/pages/has_and_belongs_to_many -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
igotimac, Thorsten L, & Bryan - Thank you all so much! You''ll ROCK! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---