Q:

Rails 4 .where nested model search

Hi,
I have a Model of Users and a Model of Products.
My Model Products belongs_to my Model User and a User has_many Products.
My question is how can i search 1 or multiple products matching a user attribute?
exemple: Product.where(price: 10) for user.where(id: 2)
What is the solution for nested model search, i'm a bit lost.
Many Thanks

A:

Since products belongs to user (and user has_many products), you can query off of the relation:
user = User.find(2)
products = user.products.where(price: 10)

