Rails habtm joins

前端 未结 2 1282
挽巷
挽巷 2021-01-02 10:26

I have this relationship between categories, products & brands:

class Brand < ActiveRecord::Base
  has_many :products
end

class Cate         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 11:18

    You did the right thing with the join, just add a more complex where definition:

    Category.joins(:products).where(:products => {:brand_id => 1})
    

提交回复
热议问题