Efficient way to query on children based on a parent filter mongo mapper

52 Views Asked by At

Here are the two models I have:

 class Parent
  many :children
  key name
 end

 class Children
  belongs_to :parent
  key price
  key description
 end

I want to find all the children that have a parent with a particular name let's say test.

I could this with

Children.all.select{|a| a.parent.name == "test"}

But I would like to define a scope in the children class is that possible using where clause?

I tried with

scope :parent_name, where("parent.name" => "test")

But it does not work.

0

There are 0 best solutions below