diff --git a/app/models/location.rb b/app/models/location.rb index 728caf49d..03af24a94 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -133,10 +133,9 @@ class Location < ApplicationRecord scope.pluck("ARRAY_AGG(id)") } - scope :duplicate_sets_within_duplicate_schemes, lambda { + scope :duplicate_sets_within_given_schemes, lambda { scope = visible .group(*DUPLICATE_LOCATION_ATTRIBUTES - %w[scheme_id]) - .where(scheme_id: nil) .where.not(postcode: nil) .where.not(mobility_type: nil) .having( @@ -145,7 +144,7 @@ class Location < ApplicationRecord scope.pluck("ARRAY_AGG(id)") } - DUPLICATE_LOCATION_ATTRIBUTES = %w[postcode mobility_type].freeze + DUPLICATE_LOCATION_ATTRIBUTES = %w[scheme_id postcode mobility_type].freeze LOCAL_AUTHORITIES = LocalAuthority.all.map { |la| [la.name, la.code] }.to_h enum local_authorities: LOCAL_AUTHORITIES diff --git a/lib/tasks/count_duplicates.rake b/lib/tasks/count_duplicates.rake index ef4f53ec2..e65688b4d 100644 --- a/lib/tasks/count_duplicates.rake +++ b/lib/tasks/count_duplicates.rake @@ -35,7 +35,7 @@ namespace :count_duplicates do duplicate_sets_within_duplicate_schemes = [] if organisation.owned_schemes.duplicate_sets.count.positive? organisation.owned_schemes.duplicate_sets.each do |duplicate_set| - duplicate_sets_within_duplicate_schemes += Location.where(scheme_id: duplicate_set).duplicate_sets + duplicate_sets_within_duplicate_schemes += Location.where(scheme_id: duplicate_set).duplicate_sets_within_given_schemes end duplicate_locations_within_duplicate_schemes_ids = duplicate_sets_within_duplicate_schemes.flatten