fatfreecrm / ransack_ui

Framework for building a search UI with Ransack
MIT License
18 stars 20 forks source link

Handling search for multi-select checkboxes #6

Open steveyken opened 10 years ago

steveyken commented 10 years ago

When searching for values in checkbox custom fields, ransack_ui doesn't generate the correct SQL for finding items.

Current SQL is

SELECT DISTINCT opportunities"."id" FROM "opportunities" WHERE "opportunities"."cf_engagement_stuff" = 'project funding' AND ('t'='t')

And the data in the table is stored in a YAML array format as:


---
- project funding
- option three
- ''

This would be picked up in a ransack contains query but not an 'is query. However, is is the only option as contains has disappeared in the most recent version.

Is there an easy way to get the following like query back via the contains option?

SELECT DISTINCT opportunities.id FROM "opportunities"
WHERE "opportunities"."cf_engagement_stuff" ILIKE '%project funding%' AND ('t'='t')
steveyken commented 10 years ago

Basically, swapping 'is' for 'contains' on fields that are multi-select would be awesome. Can you point me in the right direction to fix this?

steveyken commented 10 years ago

@ndbroadbent any hints on how to change an 'is' to a 'contains' will try to look at this tomorrow.

steveyken commented 10 years ago

My internal hack was to do Ransack.option_predicates.push('cont') but perhaps need to do something better here.