Skip to content

predicate containing empty string results in ignored query clause #722

@chrismagnacca

Description

@chrismagnacca

When passing a hash of query parameters to ransack, the documentation states that nil predicate values will be ignored. However, empty string values for predicates are also ignored. For example,

{
  "nameIn": [""],
  "addressIn": ["123 Fake St."]
}

If we apply the query params above to a fictional User model, the generated query would be:

SELECT `users`.* FROM `users`  WHERE ((`users`.`address` IN ('123 Fake St.'));

Additionally, the same behavior occurs when passing empty string into Eq clauses. Based on the documentation, I would expect the following query to be generated:

SELECT `users`.* FROM `users`  WHERE ((`users`.`address` IN ('123 Fake St.') AND `users`.`name` IN (''));

If this is not the desired case, then including this in the documentation would be preferred. If a user was specifying an Eq clause against Ids and (through some method) empty string ends up as the predicate value, the result set would go from 1 (in the case of Eq) to N (all records, since the idEq clause would be dropped for empty string).

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions