diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb index 8e8a9caa230..f000058ec01 100644 --- a/core/app/models/spree/shipment.rb +++ b/core/app/models/spree/shipment.rb @@ -33,7 +33,10 @@ class Shipment < Spree::Base scope :trackable, -> { where("tracking IS NOT NULL AND tracking != ''") } scope :with_state, ->(*s) { where(state: s) } # sort by most recent shipped_at, falling back to created_at. add "id desc" to make specs that involve this scope more deterministic. - scope :reverse_chronological, -> { order('coalesce(spree_shipments.shipped_at, spree_shipments.created_at) desc', id: :desc) } + scope :reverse_chronological, -> { + order(Arel.sql("coalesce(#{Spree::Shipment.table_name}.shipped_at, #{Spree::Shipment.table_name}.created_at) desc"), id: :desc) + } + scope :by_store, ->(store) { joins(:order).merge(Spree::Order.by_store(store)) } # shipment state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)