Sha256: dd263cbf23cfc27b4c6d87852bf040ca4f05b52f263f5704678d9f49afd37084

Contents?: true

Size: 542 Bytes

Versions: 13

Compression:

Stored size: 542 Bytes

Contents

class Micropost < ActiveRecord::Base
  belongs_to :user
  default_scope -> { order('created_at DESC') }
  validates :content, presence: true, length: { maximum: 140 }
  validates :user_id, presence: true

  # 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

13 entries across 13 versions & 2 rubygems

Version Path
rails_magic_renamer-2.0.0.pre.alpha spec/support/sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.11 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.10 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.9 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.8 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.7 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.6 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.5 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.4 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.3 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.2 sample_app_rails_4/app/models/micropost.rb
active_mocker-1.2.pre.1 sample_app_rails_4/app/models/micropost.rb