diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 7a3ba2f67..0703ba12c 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -103,14 +103,14 @@ class ProcedurePresentation < ApplicationRecord dossiers.each { |dossier| assert_matching_procedure(dossier) } filters[statut].group_by { |filter| filter.slice('table', 'column') } .map do |field, filters| table = field['table'] - column = sanitized_column(field) + table_column = sanitized_column(field) values = filters.pluck('value') case table when 'self' dates = values.map { |v| Time.zone.parse(v).beginning_of_day rescue nil } Filter.new( dossiers - ).where_datetime_matches(column, dates) + ).where_datetime_matches(table_column, dates) when 'type_de_champ', 'type_de_champ_private' relation = table == 'type_de_champ' ? :champs : :champs_private Filter.new( @@ -123,18 +123,18 @@ class ProcedurePresentation < ApplicationRecord dates = values.map { |v| v.to_date rescue nil } Filter.new( dossiers.includes(table) - ).where_equals(column, dates) + ).where_equals(table_column, dates) else Filter.new( dossiers .includes(table) - ).where_ilike(column, values) + ).where_ilike(table_column, values) end when 'user', 'individual' Filter.new( dossiers .includes(table) - ).where_ilike(column, values) + ).where_ilike(table_column, values) end.pluck(:id) end.reduce(:&) end @@ -174,23 +174,23 @@ class ProcedurePresentation < ApplicationRecord @dossiers = dossiers end - def where_datetime_matches(column, dates) + def where_datetime_matches(table_column, dates) dates = dates.compact.flat_map { |d| [d, d + 1.day] } if dates.present? - q = Array.new(dates.count / 2, "(#{column} BETWEEN ? AND ?)").join(' OR ') + q = Array.new(dates.count / 2, "(#{table_column} BETWEEN ? AND ?)").join(' OR ') @dossiers.where(q, *dates) else [] end end - def where_ilike(column, values) - q = Array.new(values.count, "(#{column} ILIKE ?)").join(' OR ') + def where_ilike(table_column, values) + q = Array.new(values.count, "(#{table_column} ILIKE ?)").join(' OR ') @dossiers.where(q, *(values.map { |value| "%#{value}%" })) end - def where_equals(column, values) - @dossiers.where("#{column} IN (?)", values) + def where_equals(table_column, values) + @dossiers.where("#{table_column} IN (?)", values) end end