Marnen Laibow-Koser wrote: > Piotr J. Puczyński wrote: >> Hi I have a question is it possible to create the reflective relation >> with users and friends using has_and_belongs_to. I found this post >> that is partly connected to my: >> http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/dff2032301961e2d >> >> but my issue is join table "friends_users" where I would need to >> create duplication of data when the relationship is reflective: every >> time someone create the friend I need to add two rows to the join >> table (user, friend) and (friend, user) with just swapped ids. Is >> there any better way of handling this type of relations? > > Sure. One possibility (untested): create a join model (I'd call it > Friendship) and, in its constructor, sort the two user IDs.
...or use before_save for this. Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.