I have the typical user, friendship model that does a has_many :through Self-referential, exactly like this: http://www.aldenta.com/2006/11/10/has_many-through-self-referential-example/ I have the following data in the friendships table user_id = 5 friend_id = 10 User.find(5).friends gives me the user 10 User.find(10).friends gives me [] Is that right? Should I have two records for each friendship? Thanks, GP -- 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 -~----------~----~----~----~------~----~------~--~---
> I have the typical user, friendship model that does a has_many :through > Self-referential, exactly like this: > > http://www.aldenta.com/2006/11/10/has_many-through-self-referential-example/ > > I have the following data in the friendships table > > user_id = 5 > friend_id = 10 > > User.find(5).friends gives me the user 10 > User.find(10).friends gives me [] > > Is that right? Should I have two records for each friendship?May want to consider using has_many_friends... really easy to setup, some nice helper methods tossed in as well... http://agilewebdevelopment.com/plugins/has_many_friends --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greater point, thank you. The methods request/accept/etc work great at the model level but when I try to expose that functionality through a FriendshipsController unfortunately it seems to cause an infinit loop and I end up with this in my development.log [4;36;1mUser Load (0.000000) [0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;35;1mUser Load (0.000000) [0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;36;1mUser Load (0.000000) [0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;35;1mUser Load (0.000000) [0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;36;1mUser Load (0.000000) [0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;35;1mUser Load (0.000000) [0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;36;1mUser Load (0.000000) [0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;35;1mUser Load (0.000000) [0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;36;1mUser Load (0.000000) [0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;35;1mUser Load (0.000000) [0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;36;1mUser Load (0.000000) [0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;35;1mUser Load (0.015000) [0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;36;1mUser Load (0.000000) [0m [0;1mSystemStackError: stack level too deep: SELECT * FROM `users` WHERE (`users`.`id` = 11) [0m [4;35;1mUser Load (0.000000) [0m [0mRuntimeError: Packets out of order: 1<>3: SELECT * FROM `users` WHERE (`users`.`id` = 11) [0m Philip Hallstrom wrote:>> User.find(5).friends gives me the user 10 >> User.find(10).friends gives me [] >> >> Is that right? Should I have two records for each friendship? > > May want to consider using has_many_friends... really easy to setup, > some > nice helper methods tossed in as well... > > http://agilewebdevelopment.com/plugins/has_many_friends-- 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 -~----------~----~----~----~------~----~------~--~---