Self-Referential Association In Rails

rails g resource friendship user_id:integer friend_id:integer
belongs_to :user
belongs_to :friend, :class_name => “User”
has_many :friendships
has_many :friends, :through => :friendships
def create
Friendship.create(
user_id: params[:user_id],
friend_id: params[friend_id]
)
end

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store