Amaç, aşağıdaki sql komutunun kullandığı bir tabloyu çoğaltmaktır. .. "Ürünler" INNER JOIN "products_promotion_rules" "ürünler" AÇIK "id" = "products_promotion_rules" "product_id" "ürünler" DANBu sql aramayı kullanan raylarda bir kopya ilişkisi oluşturma
SEÇ "ürünler" *:
SQL komutu. . "deleted_at" IS NULL AND "products_promotion_rules" "promotion_rule_id" = $ 1
Benim Raylar dernek şöyle görünür:.
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
Yukarıdaki rayları kullanmayı denedim, ancak bu product_promotion_rules tablosunun bulunmadığına dair bir hata alıyorum, ayrıca Promotion::Rules::ProductValue::ProductPromotionRule is an uninitialized constant
.
, "productsPromotionRule" ürününün "products_promotion_rules" adlı bir tablo adı olmasını istiyorsunuz. İlişkilendirme adlarını –