app/models/relationship.rb
# == Schema Information
#
# Table name: relationships
#
# id :integer not null, primary key
# follower_id :integer not null
# followed_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_relationships_on_followed_id (followed_id)
# index_relationships_on_follower_id (follower_id)
# index_relationships_on_follower_id_and_followed_id (follower_id,followed_id) UNIQUE
#
class Relationship < ActiveRecord::Base
attr_accessible :followed_id
belongs_to :follower, class_name: "User"
belongs_to :followed, class_name: "User"
validates :follower, presence: true
validates :followed, presence: true
def self.with_users_actively_followed_by(user)
select(:followed_id).where("follower_id = ?", user)
end
end