Untitled diff

Created Diff never expires
4 removals
Words removed7
Total words16
Words removed (%)43.75
6 lines
10 additions
Words added15
Total words24
Words added (%)62.50
12 lines
def new_search_condition(column, value)
def new_search_condition(column, value)
model, column = column.split('.')
model, column, attribute = column.split('.')
model = model.constantize
model = model.constantize
casted_column = ::Arel::Nodes::NamedFunction.new('CAST', [model.arel_table[column.to_sym].as(typecast)])
if model.columns_hash[column].sql_type == 'json'
casted_column.matches("%#{sanitize_sql_like(value)}%")
Arel.sql("JSON_EXTRACT(#{column}, '$.#{attribute}')")
end
else
::Arel::Nodes::NamedFunction.new(
'CAST', [model.arel_table[column.to_sym].as(typecast)]
)
end.matches("%#{value}%")
end