Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ransack does not distinguish between "*_cont" for LIKE and "*_i_cont" for ILIKE with PostgreSQL #1421

Open
dailson-igo opened this issue May 8, 2023 · 1 comment

Comments

@dailson-igo
Copy link

Ransack version: 4.0.0

The documentation doesn't agree with what ransack does. Despite the existence of predicates, "_cont" for LIKE and "_i_cont" for ILIKE, for PostgreSQL it treats both as one thing, including the result expected by the test
predicate_spec.rb.

I believe it shouldn't be like that, since there may be performance differences between LIKE and ILIKE, in addition to diverging from the documentation.

Looking at the documentation at using-predicate which reports the following result for the "_cont" predicate

>> User.ransack(first_name_cont: 'Rya').result.to_sql
=> SELECT "users".* FROM "users" WHERE ("users".."first_name" LIKE '%Rya%')

And the matching page at search-matches which reports the following match for the predicate "_cont"

Predicate: *_cont
Description: Contains value
Notes: use LIKE

When I run the query in my environment with PostgreSQL, the result is different:

irb> Common::Person.ransack(name_cont: 'Assem').result.to_sql
=> "SELECT \"common_people\".* FROM \"common_people\" WHERE \"common_people\".\"name\" ILIKE '%Assem%'"
@agrberg
Copy link

agrberg commented Sep 2, 2023

Just noticed this myself so thank you for making the issue so I know I'm not imaging things 😆

FWIW I almost always want case insensitive searching but w/ this bug there doesn't appear to be an option for case sensitive search using Ransack should I need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants