In some cases, you may want to have multiple foreign keys map to a single model. The following example explains how the “user_id” and “favorite_id” in a single table(Favourites) map to the User Model(table).
class Favourite < ActiveRecord::Base
belongs_to :user
belongs_to :favourite_user, :class_name => “User”, :foreign_key => “favourite_id”
end
Now you can play around without any issues.
(E.g)
<%= favourite.favourite_user.email %>
<%= favourite.user.email %>