sms-pager/app/models/child.rb

27 lines
588 B
Ruby
Raw Permalink Normal View History

2015-09-18 15:50:52 -05:00
class Child < ActiveRecord::Base
has_many :parenthoods
has_many :parents, through: :parenthoods, source: :person
validates :first_name, presence: true
validates :last_name, presence: true
2015-10-03 08:04:16 -05:00
scope :not_related_to, lambda { |parent_id|
joins("LEFT JOIN (
SELECT child_id
FROM parenthoods
WHERE person_id = #{sanitize(parent_id)}
) as s1 on s1.child_id = children.id")
.where("s1.child_id is null")
.order(:first_name, :last_name)
.uniq
}
2015-09-18 15:50:52 -05:00
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