diff --git a/app/models/spree/taxon.rb b/app/models/spree/taxon.rb index 57d4c94e97b..09c772fdf06 100644 --- a/app/models/spree/taxon.rb +++ b/app/models/spree/taxon.rb @@ -28,15 +28,15 @@ def seo_title # # Optionally, specify some enterprise_ids to scope the results def self.supplied_taxons(enterprise_ids = nil) - taxons = Spree::Taxon. - joins(variants: :supplier). - select('spree_taxons.*, enterprises.id AS enterprise_id') + taxons = Spree::Taxon.joins(variants: :supplier) taxons = taxons.where(enterprises: { id: enterprise_ids }) if enterprise_ids.present? - taxons.each_with_object({}) do |t, collection| - collection[t.enterprise_id.to_i] ||= Set.new - collection[t.enterprise_id.to_i] << t.id + taxons + .pluck('spree_taxons.id, enterprises.id AS enterprise_id') + .each_with_object({}) do |(taxon_id, enterprise_id), collection| + collection[enterprise_id.to_i] ||= Set.new + collection[enterprise_id.to_i] << taxon_id end end