Rails - children of multiple parents
ruby-on-rails, ruby-on-rails-3
Solution
Child.where(:parent_id => @parents.pluck(:id))
or
@parent_ids = Parent.where("[various conditions]").pluck(:id)
Child.where(:parent_id => @parent_ids}
or u can use join
Child.join(:parent).merge(Parent.where("[various conditions]")) #!!readonly
Problem
If I have two models - `parent` and `child`, and parent has_many children, and I have an array of parents and want to retrieve all of the children for all of those parents, is there a way I can do this in Rails without writing the SQL statement manually? This is what I want to do: ``` @parents = Parent.where("[various conditions]") @children = @parents.children ```