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
Post a Comment