sms-pager/app/models/person.rb

26 lines
523 B
Ruby
Raw Normal View History

2015-09-18 15:50:52 -05:00
class Person < ActiveRecord::Base
has_many :parenthoods
has_many :children, through: :parenthoods
validates :first_name, presence: true
validates :last_name, presence: true
scope :with_name, lambda { |name|
where("concat(first_name, ' ', last_name) RLIKE ?", name)
}
scope :just_parents, lambda {
joins(:children)
.order(:first_name)
.uniq
}
scope :staff, -> { where(staff: true) }
scope :admins, -> { where(admin: true) }
def name
"#{first_name} #{last_name}"
end
end