From f1e4612c0571777bfa6a69aa3930a2610a640e12 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 24 Mar 2021 11:07:07 +0000 Subject: [PATCH] Update deprecated uses of #uniq Enumerable#uniq is fine (eg calling #uniq on an Array object), but now using #uniq on an ActiveRecord::Relation is deprecated in favour of #distinct (which modifies the query itself, as opposed to iterating over the results of the query). --- app/models/schedule.rb | 2 +- lib/open_food_network/sales_tax_report.rb | 2 +- lib/tasks/data.rake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/schedule.rb b/app/models/schedule.rb index 3b94059c20..9450b160b5 100644 --- a/app/models/schedule.rb +++ b/app/models/schedule.rb @@ -3,7 +3,7 @@ class Schedule < ActiveRecord::Base has_many :order_cycle_schedules, dependent: :destroy has_many :order_cycles, through: :order_cycle_schedules - has_many :coordinators, -> { uniq }, through: :order_cycles + has_many :coordinators, -> { distinct }, through: :order_cycles scope :with_coordinator, lambda { |enterprise| joins(:order_cycles).where('coordinator_id = ?', enterprise.id).select('DISTINCT schedules.*') } diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb index 83bfadd8b6..af50c3cc85 100644 --- a/lib/open_food_network/sales_tax_report.rb +++ b/lib/open_food_network/sales_tax_report.rb @@ -70,7 +70,7 @@ module OpenFoodNetwork def relevant_rates return @relevant_rates unless @relevant_rates.nil? - @relevant_rates = Spree::TaxRate.uniq + @relevant_rates = Spree::TaxRate.distinct end def totals_of(line_items) diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 33ac11f020..a8255b96bc 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -41,7 +41,7 @@ namespace :ofn do # For each variant in the exchange products = Spree::Product.joins(:variants_including_master).where('spree_variants.id IN (?)', exchange.variants).pluck(:id).uniq - producers = Enterprise.joins(:supplied_products).where("spree_products.id IN (?)", products).uniq + producers = Enterprise.joins(:supplied_products).where("spree_products.id IN (?)", products).distinct producers.each do |producer| next if producer == exchange.receiver