Sha256: 4ca9ea47bb14e23cb973aaffd1bf448ea677d14449d1851e665743dce181256e

Contents?: true

Size: 442 Bytes

Versions: 5

Compression:

Stored size: 442 Bytes

Contents

class Micropost < ActiveRecord::Base
  belongs_to :user
  default_scope -> { order('created_at DESC') }

  # Returns microposts from the users being followed by the given user.
  def self.from_users_followed_by(user)
    followed_user_ids = "SELECT followed_id FROM relationships
                         WHERE follower_id = :user_id"
    where("user_id IN (#{followed_user_ids}) OR user_id = :user_id",
          user_id: user.id)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_mocker-1.3.2 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.3.1 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.3 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.4 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.3 sample_app_rails_4/app/models/micropost.rb