Created
January 24, 2014 18:52
-
-
Save 0xjmp/8603642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Relationship < ActiveRecord::Base | |
belongs_to :follower, class_name: "User" | |
belongs_to :followed, class_name: "User" | |
validates :follower_id, presence: true | |
validates :followed_id, presence: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_many :relationships, foreign_key: "follower_id", dependent: :destroy | |
has_many :followed_users, through: :relationships, source: :followed | |
has_many :reverse_relationships, foreign_key: "followed_id", | |
class_name: "Relationship", | |
dependent: :destroy | |
has_many :followers, through: :reverse_relationships, source: :follower | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment