我类别之间的这种关系,产品&品牌:的Rails的habtm加入
class Brand < ActiveRecord::Base
has_many :products
end
class Category < ActiveRecord::Base
has_and_belongs_to_many :products
end
class Product < ActiveRecord::Base
has_and_belongs_to_many :categories
belongs_to :brand
end
如何选择跟这个有关系的所有类别的指定品牌? 我试试这个,但得到一个错误
b = Brand.find(1)
Category.joins(:products).where(:products => b.products)