3

私は次のモデルを持っています:

class Product < ActiveRecord::Base
  has_many :product_recommendation_sets, :dependent => :destroy
  has_many :recommendation_sets, :through => :product_recommendation_sets
end

class ProductRecommendationSet < ActiveRecord::Base
  belongs_to :product
  belongs_to :recommendation_set
end

class RecommendationSet < ActiveRecord::Base  
  has_many :product_recommendation_sets, :dependent => :destroy
  has_many :products, :through => :product_recommendation_sets

  has_many :recommendation_recommendation_sets, :dependent => :destroy
  has_many :recommendations, :through => :recommendation_recommendation_sets
end

class RecommendationRecommendationSet < ActiveRecord::Base
  belongs_to :recommendation
  belongs_to :recommendation_set
end

class Recommendation < ActiveRecord::Base
   has_many :recommendation_recommendation_sets, :dependent => :destroy
   has_many :recommendations, :through => :recommendation_recommendation_sets
end

recommendations次のようにして、 product_id = の場所をすべて選択しようとしてxいます。

RecommendationSet.joins(:products, :recommendations).where(product_id:1)

ただし、不明な列エラーが発生します。特定の product_id ですべての推奨事項を選択するにはどうすればよいですか。疑似コード: recommendation_setswhereを検索しproduct_id = ?ます。recommendationsどこを探しますrecommendation_set_id = ?

4

1 に答える 1