I use two models:
Productgroup
has_ancestry
has_many :products
Product
belongs_to :productgroup
The product model is using the attribute "active".
Now I would like to scope the Productgroup model to get only productgroups with active products. There may be root productgroups with no products but with childs that have active products. So I'm looking for something like this:
@productgroups = Productgroup.includes(:products).where("productgroups.children.products.active IS ?", true)
Does anyone has an idea how to do this?