34 lines
733 B
Ruby
34 lines
733 B
Ruby
class Person < ActiveRecord::Base
|
|
has_many :parenthoods
|
|
has_many :children, through: :parenthoods
|
|
accepts_nested_attributes_for :children, reject_if: :all_blank
|
|
|
|
validates :first_name, presence: true
|
|
validates :last_name, presence: true
|
|
validates :phone, presence: true
|
|
|
|
scope :with_name, lambda { |name|
|
|
where("concat(first_name, ' ', last_name) RLIKE ?", name)
|
|
}
|
|
|
|
scope :just_parents, lambda {
|
|
joins(:children)
|
|
.order(:first_name, :last_name)
|
|
.uniq
|
|
}
|
|
|
|
scope :pageable, -> { where('phone is not NULL').order(:first_name) }
|
|
|
|
scope :staff, -> { where(staff: true) }
|
|
|
|
scope :admins, -> { where(admin: true) }
|
|
|
|
def name
|
|
"#{first_name} #{last_name}"
|
|
end
|
|
|
|
def to_i
|
|
id
|
|
end
|
|
end
|