2016-04-01 5 views
0

私はプロモーションを通じて商品にアクセスしようとしていますが、できません。コマンドラインでプロモーションルールから製品が動作しないための対応

:Promotion.last.promotion_rules.first.products

が初期化されていない定数のエラーを返します。ここで

は私の団体です:

has_many :product_promotion_rules, class_name: 'ProductPromotionRule', foreign_key: :product_id 
has_many :promotion_rules, through: :product_promotion_rules, source: :promotion_rule 

そしてPromotionRuleモデル内:製品モデルの試みの中で

class Product 
    has_many :product_promotion_rules, class_name: 'ProductPromotionRule' 
    has_many :promotion_rules, through: :product_promotion_rules 
end 

class ProductPromotionRule 
    belongs_to :product 
    belongs_to :promotion_rule 
end 

class PromotionRule 
    has_many :product_promotion_rules, class_name: 'ProductPromotionRule', join_table: 'products_promotion_rules', foreign_key: :promotion_rule_id 
    has_many :products, through: :product_promotion_rules 
    belongs_to :promotion 
end 

class Promotion 
    has_many :promotion_rules 
end 
+0

エラーを表示してください。 – MTarantini

+0

NameError:初期化されていない定数Promotion :: Rules :: ProductValue :: ProductPromotionRule –

答えて

0

has_many :products, through: :product_promotion_rules, source: :product 

更新:これを見、これを使用削除/修正したい場合があります:

join_table: products_promotion_rules 

のいずれかの変更:

join_table: product_promotion_rules 

か、それを削除してください。

+0

同じエラーが発生しました... NameError:初期化されていない定数Promotion :: Rules :: ProductValue :: ProductPromotionRule –

+0

残念ながら私はまだ同じエラーが発生しています –

関連する問題