且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在另一个表中查找具有两条特定记录的记录

更新时间: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