activerecord - Rails, including more than one relationship in the scope of a model -


i have following scope returns products have branch_id = 1, , have attribute enabled set true.

scope :enabled_product, -> {includes(:products).where("products.branch_id = ?", 1).where(products: {enabled: true})} 

product has many many relationship category. how can include categories each product in scope?

includes(:products => [:categories]) 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -