Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Change HABTM relations to has_many through (#11505)

Aleksandar Petrushev55d27ec8386c
diff --git a/core/app/models/spree/payment_method.rb b/core/app/models/spree/payment_method.rb
index f6a7f08a05..79aef5d0ef 100644
--- a/core/app/models/spree/payment_method.rb
+++ b/core/app/models/spree/payment_method.rb
@@ -15,7 +15,8 @@ module Spree
validates :name, presence: true
- has_and_belongs_to_many :stores
+ has_many :store_payment_methods, class_name: 'Spree::StorePaymentMethod'
+ has_many :stores, class_name: 'Spree::Store', through: :store_payment_methods
with_options dependent: :restrict_with_error do
has_many :payments, class_name: 'Spree::Payment', inverse_of: :payment_method
diff --git a/core/app/models/spree/promotion.rb b/core/app/models/spree/promotion.rb
index 4c75ff0408..d9dd4488d7 100644
--- a/core/app/models/spree/promotion.rb
+++ b/core/app/models/spree/promotion.rb
@@ -19,7 +19,8 @@ module Spree
has_many :order_promotions, class_name: 'Spree::OrderPromotion'
has_many :orders, through: :order_promotions, class_name: 'Spree::Order'
- has_and_belongs_to_many :stores, class_name: 'Spree::Store', join_table: 'spree_promotions_stores'
+ has_many :store_promotions, class_name: 'Spree::StorePromotion'
+ has_many :stores, class_name: 'Spree::Store', through: :store_promotions
accepts_nested_attributes_for :promotion_actions, :promotion_rules