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 :users, :through => :friendships
class Friendship< ActiveRecord::Base
belongs_to :User #?
create_table “users” do |t|
t.column “name”, :string
create_table “friendships” do |t|
t.column “user_id”, :integer
t.column “user_id”, :integer #?