fix(filter): filtering types_de_champs by enum should not ilike. nows it search by exact match since enum are normalized so findable with simple where

This commit is contained in:
mfo 2024-09-24 20:38:48 +02:00
parent 1339e10280
commit 75063ae31e
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
2 changed files with 13 additions and 2 deletions

View file

@ -33,5 +33,11 @@ module DossierFilteringConcern
q = Array.new(values.count, "(#{table_column} ILIKE ?)").join(' OR ') q = Array.new(values.count, "(#{table_column} ILIKE ?)").join(' OR ')
where(q, *(values.map { |value| "%#{value}%" })) where(q, *(values.map { |value| "%#{value}%" }))
} }
scope :filter_enum, lambda { |table, column, values|
table_column = ProcedurePresentation.sanitized_column(table, column)
q = Array.new(values.count, "(#{table_column} = ?)").join(' OR ')
where(q, *(values))
}
end end
end end

View file

@ -220,8 +220,13 @@ class ProcedurePresentation < ApplicationRecord
dossiers.where("dossiers.#{column} IN (?)", values) dossiers.where("dossiers.#{column} IN (?)", values)
end end
when TYPE_DE_CHAMP when TYPE_DE_CHAMP
dossiers.with_type_de_champ(column) if dossier_column.type == :enum
.filter_ilike(:champs, value_column, values) dossiers.with_type_de_champ(column)
.filter_enum(:champs, value_column, values)
else
dossiers.with_type_de_champ(column)
.filter_ilike(:champs, value_column, values)
end
when 'etablissement' when 'etablissement'
if column == 'entreprise_date_creation' if column == 'entreprise_date_creation'
dates = values dates = values