2015-09-18 15:50:52 -05:00
|
|
|
class Person < ActiveRecord::Base
|
|
|
|
has_many :parenthoods
|
|
|
|
has_many :children, through: :parenthoods
|
2015-09-24 22:00:26 -05:00
|
|
|
accepts_nested_attributes_for :children
|
2015-09-18 15:50:52 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
end
|