ruby - Rails ActiveRecord joining to most recent child in scope -


i trying write worker has check recent child's status , queuing based on that. example, find parents oldest child in school

class parent   has_many :children end class child   belongs_to :parent   lookup_for :status, symbolize: true end 

currently scope is:

parent.joins(:children).       where("children.birth_date =             (select max(children.birth_date)              children              children.parent_id = parents.parent_id").       where('children.status = ?', status[:in_school]').pluck(:parent_id) 

seems there should better way this. ideas

to clarify looking parents who's oldest child still in school

if using first/or last child lot in queries, add them fields in parent

class parent   belongs_to :youngest_child, class_name: child, inverse_of: :parent end 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -