In my RoR application, I have a database search similar to this:
Client.joins(:products).where({'product.id' => [1,2,3]})
Unfortunately, this will return all customers who bought product 1, 2 or 3, but I only want to return customers who bought all of the three products. In other words, I would like to write a query that matches for n elements in a given set.
Are there any elegant solutions for this?
source
share