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.

Fix MySQL error with upsert_all

Damian Legawiec69e8333b36db
diff --git a/core/app/models/spree/price_list.rb b/core/app/models/spree/price_list.rb
index 02687071bb..4d0d0d398e 100644
--- a/core/app/models/spree/price_list.rb
+++ b/core/app/models/spree/price_list.rb
@@ -177,11 +177,10 @@ module Spree
return true if records_to_upsert.empty?
- Spree::Price.upsert_all(
- records_to_upsert,
- unique_by: :id,
- update_only: [:amount, :compare_at_amount]
- )
+ opts = { update_only: [:amount, :compare_at_amount] }
+ opts[:unique_by] = :id unless ActiveRecord::Base.connection.adapter_name == 'Mysql2'
+
+ Spree::Price.upsert_all(records_to_upsert, **opts)
touch_variants(variant_ids.to_a)
true