Rails 4 .where nested model search -


hi,

i have model of users , model of products. model products belongs_to model user , user has_many products.

my question how can search 1 or multiple products matching user attribute?

exemple: product.where(price: 10) user.where(id: 2)

what solution nested model search, i'm bit lost. many thanks

since products belongs user (and user has_many products), can query off of relation:

user = user.find(2) products = user.products.where(price: 10) 

Comments