From 0f05198f485f62c17d6f3f68d708eb6561ae5c99 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 15 Mar 2021 16:50:39 +0000 Subject: [PATCH] Update any adjustments that are missing an order association --- db/migrate/20210315163900_update_associations.rb | 13 +++++++++++++ db/schema.rb | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210315163900_update_associations.rb diff --git a/db/migrate/20210315163900_update_associations.rb b/db/migrate/20210315163900_update_associations.rb new file mode 100644 index 0000000000..b954c6c582 --- /dev/null +++ b/db/migrate/20210315163900_update_associations.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 9865cb2080..ddd564122b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"