fix: make enums filter work if champs.enums contains the searched value among others
This commit is contained in:
parent
50677e982c
commit
09793420fb
4 changed files with 31 additions and 36 deletions
|
@ -37,7 +37,9 @@ class Columns::ChampColumn < Column
|
|||
if type == :enum
|
||||
relation.where(champs: { column => search_terms }).ids
|
||||
elsif type == :enums
|
||||
relation.filter_array_enum(:champs, column, search_terms).ids
|
||||
# in a multiple drop down list, the value are stored as '["v1", "v2"]'
|
||||
quoted_search_terms = search_terms.map { %{"#{_1}"} }
|
||||
relation.filter_ilike(:champs, column, quoted_search_terms).ids
|
||||
else
|
||||
relation.filter_ilike(:champs, column, search_terms).ids
|
||||
end
|
||||
|
|
|
@ -35,12 +35,6 @@ module DossierFilteringConcern
|
|||
where("#{table_column} LIKE ANY (ARRAY[?])", safe_quoted_terms)
|
||||
}
|
||||
|
||||
scope :filter_array_enum, lambda { |table, column, values|
|
||||
table_column = DossierFilterService.sanitized_column(table, column)
|
||||
q = Array.new(values.count, "(#{table_column} = ?)").join(' OR ')
|
||||
where(q, *(values. map { |value| "[\"#{value}\"]" }))
|
||||
}
|
||||
|
||||
def sanitize_sql_like(q) = ActiveRecord::Base.sanitize_sql_like(q)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue