mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Update data migration model definitions
The good_migrations gem was not working with polymorphic associations.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
# It turns out the good_migrations gem doesn't play nicely with loading classes on polymorphic
|
||||
# associations. The only workaround seems to be to load the class explicitly, which essentially
|
||||
# skips the whole point of good_migrations... :/
|
||||
require 'enterprise_fee'
|
||||
|
||||
class MigrateEnterpriseFeeTaxAmounts < ActiveRecord::Migration[5.0]
|
||||
class Spree::Adjustment < ApplicationRecord
|
||||
belongs_to :originator, -> { with_deleted }, polymorphic: true
|
||||
@@ -8,9 +13,6 @@ class MigrateEnterpriseFeeTaxAmounts < ActiveRecord::Migration[5.0]
|
||||
|
||||
scope :enterprise_fee, -> { where(originator_type: 'EnterpriseFee') }
|
||||
end
|
||||
class EnterpriseFee < ApplicationRecord
|
||||
belongs_to :tax_category, class_name: 'Spree::TaxCategory', foreign_key: 'tax_category_id'
|
||||
end
|
||||
class Spree::LineItem < ApplicationRecord
|
||||
belongs_to :variant, class_name: "Spree::Variant"
|
||||
has_one :product, through: :variant
|
||||
@@ -23,6 +25,14 @@ class MigrateEnterpriseFeeTaxAmounts < ActiveRecord::Migration[5.0]
|
||||
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
|
||||
has_many :variants, class_name: 'Spree::Variant'
|
||||
end
|
||||
class Spree::TaxCategory < ApplicationRecord
|
||||
has_many :tax_rates, dependent: :destroy, inverse_of: :tax_category
|
||||
end
|
||||
class Spree::TaxRate < ApplicationRecord
|
||||
belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates
|
||||
belongs_to :tax_category, class_name: "Spree::TaxCategory", inverse_of: :tax_rates
|
||||
has_many :adjustments, as: :originator
|
||||
end
|
||||
|
||||
def up
|
||||
migrate_enterprise_fee_taxes!
|
||||
|
||||
Reference in New Issue
Block a user