From 6f8991fc31b3ed7e0e1bbcf0d8d1cd59a05bb260 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Fri, 7 Jun 2024 12:15:12 +0100 Subject: [PATCH] Use find_each for task --- lib/tasks/fix_nil_letting_allocation_values.rake | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/tasks/fix_nil_letting_allocation_values.rake b/lib/tasks/fix_nil_letting_allocation_values.rake index e99b6de3d..770fc63d7 100644 --- a/lib/tasks/fix_nil_letting_allocation_values.rake +++ b/lib/tasks/fix_nil_letting_allocation_values.rake @@ -1,11 +1,10 @@ desc "Infer nil letting allocation values as no" task fix_nil_letting_allocation_values: :environment do - logs = LettingsLog.where(cbl: nil) - .or(LettingsLog.where(chr: nil)) - .or(LettingsLog.where(cap: nil)) - .or(LettingsLog.filter_by_year(2024).where(accessible_register: nil)) - - logs.each do |log| + LettingsLog.where(cbl: nil) + .or(LettingsLog.where(chr: nil)) + .or(LettingsLog.where(cap: nil)) + .or(LettingsLog.filter_by_year(2024).where(accessible_register: nil)) + .find_each do |log| next unless log.cbl.present? || log.chr.present? || log.cap.present? || log.accessible_register.present? || log.letting_allocation_unknown.present? log.cbl = 0 if log.cbl.blank?