Skip to content

Allow empty string and empty array as valid search values#1664

Open
pekopekopekopayo wants to merge 1 commit intoactiverecord-hackery:mainfrom
pekopekopekopayo:fix/preserve-empty-string-and-array-search-values
Open

Allow empty string and empty array as valid search values#1664
pekopekopekopayo wants to merge 1 commit intoactiverecord-hackery:mainfrom
pekopekopekopayo:fix/preserve-empty-string-and-array-search-values

Conversation

@pekopekopekopayo
Copy link
Contributor

Ransack currently discards empty strings and empty arrays from search params silently.

This might be intentional, but users may not be aware of this behavior or may not want it. If a user passes an empty array, they probably expect no results to be returned. If they pass an empty string, they probably want to find records where the field is actually empty.

Currently, passing empty values causes a full table scan because all conditions are removed. This could potentially lead to OOM issues (unless pagination is in place).

With this change:

  • name_eq: '' generates WHERE name = ''
  • id_in: [] generates WHERE 1=0 (returns no results)
  • name_eq: nil is still ignored (existing behavior preserved)

Related: #1592, #722

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

Successfully merging this pull request may close these issues.

1 participant