更新时间:2022-12-12 14:15:49
不久前我遇到了这个问题,幸好有一个很好的解决方案.
I had this problem a while back, thankfully there is a nice solution.
def self.has_taxons(taxons)
id = arel_table[:id]
Product.joins(:taxons).where(taxons: { name: taxons }).group(id).having(id.count.eq(taxons.size))
end