Skip to content

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

Description

@dailson-igo

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%'"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions