-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Hi,
I really like your approach here. I hope you have time to develop it further.
I hit an issue when running with postgres. The LIKE query fails for boolean or integer.
I'm guessing that you're testing on mysql or sqlite and they're more forgiving...
This fixes the issue for me at least:
def filtered_resources(resources)
@filterable_attributes = AdministrateFilterable::FiltererService.filter_attributes(dashboard, new_resource)
filter_params = params[resource_name]
return resources if filter_params.blank?
filter_params.each do |key, value|
next unless resources.column_names.include?(key.to_s) && value.present?
attribute_type = new_resource.class.attribute_types[key].type
case attribute_type
when :boolean
boolean_value = ActiveRecord::Type::Boolean.new.cast(value)
resources = resources.where(key => boolean_value)
when :integer
integer_value = value.to_i
resources = resources.where(key => integer_value)
else
sanitized_query = ActiveRecord::Base.send(:sanitize_sql_array, ["#{key} LIKE ?", "%#{value}%"])
resources = resources.where(sanitized_query)
end
end
resources
end
Metadata
Metadata
Assignees
Labels
No labels