Update any adjustments that are missing an order association

This commit is contained in:
Matt-Yorkley
2021-03-15 16:50:39 +00:00
parent 0d364c6b69
commit 0f05198f48
2 changed files with 14 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
class UpdateAssociations < ActiveRecord::Migration[5.0]
class Spree::Adjustment < ActiveRecord::Base
belongs_to :adjustable, polymorphic: true
belongs_to :order, class_name: "Spree::Order"
end
def up
# Updates any adjustments missing an order association
Spree::Adjustment.where(order_id: nil, adjustable_type: "Spree::Order").find_each do |adjustment|
adjustment.update_column(:order_id, adjustment.adjustable_id)
end
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20210312095840) do
ActiveRecord::Schema.define(version: 20210315163900) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"