查找列表中带有任何标签的所有产品

Find all products with any tags in list

在我的 spree 商店中,我需要在标签列表中找到具有一个或多个标签的任何产品。 spree 中的标签是使用 acts-as-taggable-on gem.

完成的

我试过

Spree::Product.joins("spree_taggings").where("taggings.id IN (?)", list_of_tag_ids )

但是好像不行。

我怎样才能通过标签查找产品?

需要用ID搜索吗?如果可以按名称搜索,则可以使用内置范围 .tagged_with

Spree::Product.tagged_with(["awesome", "cool"], :match_all => true)

文档:https://github.com/mbleigh/acts-as-taggable-on#finding-tagged-objects

如果确实需要按ID搜索,当然可以先抓取那些。

ActsAsTaggableOn::Tag.where("id IN (?)", list_of_tag_ids).pluck(:name)