Muitos para muitos registros ativos
# id email encrypted_password
class User < ActiveRecord::Base
has_many :tweets
has_many :likes
has_many :follows_as_follower, class_name: 'Follow',
foreign_key: :follower_user_id
has_many :follows_as_followed, class_name: 'Follow',
foreign_key: :followed_user_id
has_many :followed_users, through: :follows_as_follower,
source: :followed_user
has_many :followers, through: :follows_as_followed,
source: :follower_user
end
# id content user_id
class Tweet < ActiveRecord::Base
belongs_to :user
has_many :likes
end
# id follower_user_id followed_user_id
class Follow < ActiveRecord::Base
belongs_to :follower_user, class_name: 'User'
belongs_to :followed_user, class_name: 'User'
end
# id user_id tweet_id
class Like < ActiveRecord::Base
belongs_to :user
belongs_to :tweet
end
Mark Bacon