在我的狂欢商店中,我需要找到任何在标签列表中包含一个或多个标签的产品。 spree中的标签是使用act-as-taggable-on gem完成的。
我试图用
做到这一点Spree::Product.joins("spree_taggings").where("taggings.id IN (?)", list_of_tag_ids )
但它似乎无法发挥作用。
我如何通过标签查找产品?
答案 0 :(得分:1)
按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)