user.rb 572 Bytes
Newer Older
Eugen Rochko's avatar
Eugen Rochko committed
1
class User < ApplicationRecord
Eugen Rochko's avatar
Eugen Rochko committed
2
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
3

Eugen Rochko's avatar
Eugen Rochko committed
4
  belongs_to :account, inverse_of: :user
5
  accepts_nested_attributes_for :account
6

Eugen Rochko's avatar
Eugen Rochko committed
7
  validates :account, presence: true
8

9 10
  scope :prolific, -> { joins('inner join statuses on statuses.account_id = users.account_id').select('users.*, count(statuses.id) as statuses_count').group('users.id').order('statuses_count desc') }
  scope :recent,   -> { order('created_at desc') }
11
  scope :admins,   -> { where(admin: true) }
Eugen Rochko's avatar
Eugen Rochko committed
12
end