ruby on rails - Finding records with two specific records in another table -
i have product model has_and_belongs_to_many :taxons, , want find products in specific taxons.
for example, if product belongs both "ruby on rails" , "shirts" taxon, want product returned in dataset, not if belongs either "ruby on rails" or "shirts"
i had problem while back, thankfully there 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
Comments
Post a Comment