Untitled diff

Created Diff never expires
4 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
6 lines
10 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
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