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
|
|
|
|
end
|