ruby on rails - How would you represent this logic in models and migration -


this has been asked not sure how phrase suitable querying.

i wish call user1.friends (user1 instance of user model) returns list of users include user1 1 of friends.

i not sure start one.

what columns friends table? should there friends table?

maybe use railscasts

models/user.rb:

has_many :friendships has_many :friends, :through => :friendships has_many :inverse_friendships, :class_name => "friendship", :foreign_key => "friend_id" has_many :inverse_friends, :through => :inverse_friendships, :source => :user 

models/friendship.rb

belongs_to :user belongs_to :friend, :class_name => "user" 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -