多対多の関係を持つ 2 つのモデル Product と Tag があります。
class Product < ActiveRecord::Base
has_many :product_tags
has_many :tags, through: :product_tags
end
class Tag < ActiveRecord::Base
has_many :product_tags
has_many :products, through: :product_tags
end
および関係モデル:
class ProductTag < ActiveRecord::Base
belongs_to :product
belongs_to :tag
end
指定されたタグのリストで製品を検索する最適な方法は何ですか? 製品には、タグの 1 つだけでなく、すべてのタグが必要です。