目前我得到了这个:
Country.includes(products: [:categories]).where("products.categories.name = ?", "Gardening").references(products: [:categories])
这段代码有问题吗?或者我们不允许为二级子对象写条件?
答案 0 :(得分:0)
您可以通过使用获得相同的答案 Different ways of eager loading
r = Country.joins(products: [:categories]).where("products.categories.name = ?", "Gardening").preload(products: [:categories])
答案 1 :(得分:0)
为了简单起见,只需做
Country.joins(products: [:categories]).where("categories.name = ?", "Gardening")
或:
Country.joins(products: [:categories]).where(categories: {name: "Gardening"})