From 77b0e2d23f53497d500615bd4f5ae857b100f43a Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 17:12:03 +0000 Subject: [PATCH] Update has_many_through on Order Fixes: 384) Spree::OrderMailer basic behaviour doesn't aggressively escape double quotes in confirmation body Failure/Error: adjustments = adjustments.to_a + order.shipment_adjustments.to_a ActionView::Template::Error: Cannot have a has_many :through association 'Spree::Order#shipment_adjustments' which goes through 'Spree::Order#shipments' before the through association is defined. # ./app/helpers/checkout_helper.rb:10:in `checkout_adjustments_for' # ./app/views/spree/order_mailer/_order_summary.html.haml:43:in `_app_views_spree_order_mailer__order_summary_html_haml__2911251238692323485_70331958934800' # ./app/views/spree/order_mailer/confirm_email_for_customer.html.haml:23:in `_app_views_spree_order_mailer_confirm_email_for_customer_html_haml__3734564010704881256_70331959518520' # ./app/mailers/spree/order_mailer.rb:35:in `block in confirm_email_for_customer' # ./app/mailers/spree/order_mailer.rb:33:in `confirm_email_for_customer' # ./spec/mailers/order_mailer_spec.rb:20:in `block (3 levels) in ' # ------------------ # --- Caused by: --- # ActiveRecord::HasManyThroughOrderError: # Cannot have a has_many :through association 'Spree::Order#shipment_adjustments' which goes through 'Spree::Order#shipments' before the through association is defined. # ./app/helpers/checkout_helper.rb:10:in `checkout_adjustments_for' --- app/models/spree/order.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index b1731b42d4..4093c995f8 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -42,16 +42,16 @@ module Spree as: :adjustable, dependent: :destroy - has_many :line_item_adjustments, through: :line_items, source: :adjustments - has_many :shipment_adjustments, through: :shipments, source: :adjustments - has_many :all_adjustments, class_name: 'Spree::Adjustment', dependent: :destroy - has_many :shipments, dependent: :destroy do def states pluck(:state).uniq end end + has_many :line_item_adjustments, through: :line_items, source: :adjustments + has_many :shipment_adjustments, through: :shipments, source: :adjustments + has_many :all_adjustments, class_name: 'Spree::Adjustment', dependent: :destroy + belongs_to :order_cycle belongs_to :distributor, class_name: 'Enterprise' belongs_to :customer