Skip to content

Conversation

@tatematsu-k
Copy link

Summary

Implements predicates to search by string length as requested in #1492.

Changes

  • Added length_eq, length_lt, length_lteq, length_gt, length_gteq predicates
  • These predicates wrap the attribute in LENGTH() or CHAR_LENGTH() function based on the database adapter
  • Added comprehensive tests for all length predicates

Usage

# Find records where name length is less than or equal to 4
Person.ransack(name_length_lteq: 4).result

# Find records where name length equals 10
Person.ransack(name_length_eq: 10).result

Database Support

  • PostgreSQL/PostGIS: Uses CHAR_LENGTH()
  • MySQL: Uses CHAR_LENGTH()
  • SQLite and others: Uses LENGTH()

Closes #1492

Implements predicates to search by string length:
- length_eq: equals
- length_lt: less than
- length_lteq: less than or equal
- length_gt: greater than
- length_gteq: greater than or equal

These predicates wrap the attribute in LENGTH() or CHAR_LENGTH()
function based on the database adapter.

Closes activerecord-hackery#1492
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.

Predicate to search by length of string

1 participant