Hi I want to represent a social graph in my facebooker application. I have a class user and I want to connect each user to his friends using many-to-many. I am planning to support other networks in the future so I have to keep that in mind what''s the best way to implement this ? My idea is to create a friendship table that holds user_id, user_id and create a has_many :through relationship. I''m not sure how to do it when the two models are the same. class User < ActiveRecord::Base has_many :friendships has_many :users, :through => :friendships end class Friendship< ActiveRecord::Base belongs_to :User belongs_to :User #? end create_table "users" do |t| t.column "name", :string end create_table "friendships" do |t| t.column "user_id", :integer t.column "user_id", :integer #? end -- 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 -~----------~----~----~----~------~----~------~--~---
another question. since it''s a mutual friendship some entries might be : user_id, user_id : preson1, person2 person2, person1 is this duplication a problem ? how do i handle it ? -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Gady, The RailsSpace application code could help you a lot on this matter as it has the exact same structure. You can get it there http://railsspace.com/book The book itself would probably be of great interest if you''re going to build that kind of community :) Gedeon On Apr 15, 11:16 pm, Gady Sujo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> another question. > since it''s a mutual friendship some entries might be : > user_id, user_id : > > preson1, person2 > person2, person1 > > is this duplication a problem ? how do i handle it ? > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Gedeon wrote:> Hi Gady, > > The RailsSpace application code could help you a lot on this matter as > it has the exact same structure. > > > You can get it there http://railsspace.com/book > The book itself would probably be of great interest if you''re going to > build that kind of community :) > > Gedeon > > On Apr 15, 11:16 pm, Gady Sujo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >> another question. >> since it''s a mutual friendship some entries might be : >> user_id, user_id : >> >> preson1, person2 >> person2, person1 >> >> is this duplication a problem ? how do i handle it ? >>Duplication is always a problem. You might simply force the person1_id being less (or equal for narcissic people) than person2_id. Lionel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
http://agilewebdevelopment.com/plugins/has_many_friends Good starting point is the source their. -- 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 -~----------~----~----~----~------~----~------~--~---