sms-pager/app/models/person.rb

34 lines
733 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
2015-10-03 08:04:16 -05:00
accepts_nested_attributes_for :children, reject_if: :all_blank
2015-09-18 15:50:52 -05:00
validates :first_name, presence: true
validates :last_name, presence: true
2015-10-03 08:04:16 -05:00
validates :phone, presence: true
2015-09-18 15:50:52 -05:00
scope :with_name, lambda { |name|
where("concat(first_name, ' ', last_name) RLIKE ?", name)
}
scope :just_parents, lambda {
joins(:children)
2015-10-03 19:16:46 -05:00
.order(:first_name, :last_name)
2015-09-18 15:50:52 -05:00
.uniq
}
2015-09-20 22:30:44 -05:00
scope :pageable, -> { where('phone is not NULL').order(:first_name) }
2015-09-18 15:50:52 -05:00
scope :staff, -> { where(staff: true) }
scope :admins, -> { where(admin: true) }
def name
"#{first_name} #{last_name}"
end
2015-10-03 15:15:19 -05:00
def to_i
id
end
2015-09-18 15:50:52 -05:00
end