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
The RailsSpace application code could help you a lot on this matter as
it has the exact same structure.
You can get it there Railsspace.com is for sale | HugeDomains
The book itself would probably be of great interest if you’re going to
build that kind of community