The title may be somehow puzzling. Suppose an Social Networking Site, we have one table to keep each person''s id and name. Then we need the function to have friends, so we''ll have to create a table to store the information that two persons are friends. So this table will contain two columns, both of them referring to one person. But the problem here is there''s no order here, which means one pair of friends are stored in just one row, (Person A - Person B or Person B - Person A, whichever comes into database first). In this scheme, ActiveRecord will have trouble if I use "has_and_belongs_to_many", since if I call person.friends (suppose this is name of the table to store friend information), ActiveRecord will only look up in one column of friends table, either first or second, depending the name of column assigned. So could anybody tell me how to deal with this kind of problem? I searched this group, and found a similar topic, "ActiveRecord: Reference same table twice", but this one there''s an order in two columns so there''ll be no problem. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Nov-11 09:55 UTC
Re: Possibility of ActiveRecord in combining two same tables
Make two entries, one for each "direction" A is friend of B B is friend of A --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---