2016-04-01 3 views
0

Ich versuche, auf Produkte über die Werbeaktion zuzugreifen, dies jedoch nicht.Zuordnung von der Werberichtlinie zum Produkt funktioniert nicht

In der Befehlszeile: Promotion.last.promotion_rules.first.products

Gibt einen Fehler eines nicht initialisierten konstant.

Hier sind meine Assoziationen:

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

Bitte den Fehler anzeigen. – MTarantini

+0

NameError: nicht initialisierte Konstante Promotion :: Regeln :: ProductValue :: ProductPromotionRule –

Antwort

0

Innerhalb des Produktmodell Versuch:

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

Und im PromotionRule Modell:

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

Update: das sah, was Sie Möchten Sie möglicherweise entfernen/beheben:

join_table: products_promotion_rules 

Entweder Änderung:

join_table: product_promotion_rules 

oder versuchen, es zu entfernen.

+0

Den gleichen Fehler bekommen ... NameError: nicht initialisierte Konstante Promotion :: Regeln :: ProductValue :: ProductPromotionRule –

+0

Leider bekomme ich immer noch den gleichen Fehler –

Verwandte Themen