From eb5c37daca038adfe514472a6605eb66de06b0b6 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 17:03:28 +0000 Subject: [PATCH] Change order of declaration for has_many_through association with it's parent Fixes: 292) OrderManagement::Subscriptions::ProxyOrderSyncer#sync! when the subscription is not persisted and the schedule includes upcoming oc that closes after ends_at does not create a new proxy order for that oc Failure/Error: order_cycle.schedules << schedule ActiveRecord::HasManyThroughOrderError: Cannot have a has_many :through association 'OrderCycle#schedules' which goes through 'OrderCycle#order_cycle_schedules' before the through association is defined. # ./spec/factories.rb:29:in `block (4 levels) in ' # ./spec/factories.rb:28:in `each' # ./spec/factories.rb:28:in `block (3 levels) in ' # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:59:in `block (4 levels) in ' # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:65:in `block (4 levels) in ' # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:133:in `block (6 levels) in ' # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:133:in `block (5 levels) in ' --- app/models/order_cycle.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 93451f081c..91230b3aec 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -16,8 +16,8 @@ class OrderCycle < ActiveRecord::Base has_many :suppliers, -> { distinct }, source: :sender, through: :cached_incoming_exchanges has_many :distributors, -> { distinct }, source: :receiver, through: :cached_outgoing_exchanges - has_many :schedules, through: :order_cycle_schedules has_many :order_cycle_schedules + has_many :schedules, through: :order_cycle_schedules has_paper_trail meta: { custom_data: proc { |order_cycle| order_cycle.schedule_ids.to_s } } attr_accessor :incoming_exchanges, :outgoing_exchanges