diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 136edfad8..d70f9cbff 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -59,8 +59,8 @@ class LettingsLog < Log query.all } scope :search_by, lambda { |param| - sanitized_order_param = ActiveRecord::Base.sanitize_sql_for_order(param) - order_param_without_spaces = sanitized_order_param.delete(" ") + sanitized_param = ActiveRecord::Base.sanitize_sql(param) + param_without_spaces = sanitized_param.delete(" ") by_id = Arel.sql("CASE WHEN lettings_logs.id = ? THEN 0 ELSE 1 END") by_tenant_code = Arel.sql("CASE WHEN tenancycode = ? THEN 0 WHEN tenancycode ILIKE ? THEN 1 ELSE 2 END") @@ -73,10 +73,10 @@ class LettingsLog < Log .or(filter_by_postcode(param)) .or(filter_by_id(param.gsub(/log/i, ""))) .order( - [by_id, sanitized_order_param.to_i], - [by_tenant_code, sanitized_order_param, sanitized_order_param], - [by_propcode, sanitized_order_param, sanitized_order_param], - [by_postcode, order_param_without_spaces, order_param_without_spaces], + [by_id, sanitized_param.to_i], + [by_tenant_code, sanitized_param, sanitized_param], + [by_propcode, sanitized_param, sanitized_param], + [by_postcode, param_without_spaces, param_without_spaces], ) } scope :after_date, ->(date) { where("lettings_logs.startdate >= ?", date) } diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 1c748582e..aca80ef94 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -46,8 +46,8 @@ class SalesLog < Log } scope :filter_by_purchaser_code, ->(purchid) { where("purchid ILIKE ?", "%#{purchid}%") } scope :search_by, lambda { |param| - sanitized_order_param = ActiveRecord::Base.sanitize_sql_for_order(param) - order_param_without_spaces = sanitized_order_param.delete(" ") + sanitized_param = ActiveRecord::Base.sanitize_sql(param) + param_without_spaces = sanitized_param.delete(" ") by_id = Arel.sql("CASE WHEN id = ? THEN 0 ELSE 1 END") by_purchaser_code = Arel.sql("CASE WHEN purchid = ? THEN 0 WHEN purchid ILIKE ? THEN 1 ELSE 2 END") @@ -56,9 +56,9 @@ class SalesLog < Log filter_by_purchaser_code(param) .or(filter_by_postcode(param)) .or(filter_by_id(param.gsub(/log/i, ""))) - .order([by_id, sanitized_order_param.to_i], - [by_purchaser_code, sanitized_order_param, sanitized_order_param], - [by_postcode, order_param_without_spaces, order_param_without_spaces]) + .order([by_id, sanitized_param.to_i], + [by_purchaser_code, sanitized_param, sanitized_param], + [by_postcode, param_without_spaces, param_without_spaces]) } scope :age1_answered, -> { where.not(age1: nil).or(where(age1_known: [1, 2])) } scope :duplicate_logs, lambda { |log|