From ba05503baa29b1e848d37067b46b0d2d640b8559 Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Wed, 3 Oct 2018 09:34:52 +0200 Subject: [PATCH] Use ActiveRecord relation for Spree::Shipment#line_items The original plain ruby instance method has been replaced by an ActiveRecord `has_many` relation. This pure SQL solution should improve a bit performances and allow to add further relations using `has_many ... through: line_items`. --- core/app/models/spree/shipment.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb index 67203f8e9c0..8e8a9caa230 100644 --- a/core/app/models/spree/shipment.rb +++ b/core/app/models/spree/shipment.rb @@ -13,6 +13,7 @@ class Shipment < Spree::Base has_many :shipping_methods, through: :shipping_rates has_many :state_changes, as: :stateful has_many :cartons, -> { distinct }, through: :inventory_units + has_many :line_items, -> { distinct }, through: :inventory_units before_validation :set_cost_zero_when_nil @@ -188,10 +189,6 @@ def item_cost line_items.map(&:total).sum end - def line_items - inventory_units.includes(:line_item).map(&:line_item).uniq - end - def ready_or_pending? ready? || pending? end