I am currently trying to write a worker that has to check the most recent child's status and queuing it based on that. For example, find parents whose oldest child is in school
class Parent
has_many :children
end
class Child
belongs_to :parent
lookup_for :status, symbolize: true
end
Currently my scope is:
Parent.joins(:children).
where("children.birth_date =
(SELECT MAX(children.birth_date)
FROM children
WHERE children.parent_id = parents.parent_id").
where('children.status = ?', Status[:in_school]').pluck(:parent_id)
Seems like there should be a better way to do this. Any ideas
To Clarify I am looking for all the Parents who's oldest child is still in school