Skip to content

fix(drizzle): convert equals/not_equals to in/not_in for hasMany relationship array values#15766

Open
maximseshuk wants to merge 2 commits intopayloadcms:mainfrom
maximseshuk:fix/sanitize-query-value-array
Open

fix(drizzle): convert equals/not_equals to in/not_in for hasMany relationship array values#15766
maximseshuk wants to merge 2 commits intopayloadcms:mainfrom
maximseshuk:fix/sanitize-query-value-array

Conversation

@maximseshuk
Copy link
Contributor

What?

When the value is an array, converts equalsin and not_equalsnot_in for relationship/upload fields in sanitizeQueryValue.

Why?

When filtering relationship fields with equals or not_equals using array values (e.g., { relatedPost: { equals: [1] } }), SQL adapters (Postgres, SQLite) throw because the = operator doesn't accept arrays.

How?

Added an Array.isArray(formattedValue) guard at the end of sanitizeQueryValue that swaps the operator when the value is an array. It runs after all type conversions (UUID validation, date formatting, ID casting) so it works with already-sanitized values. Same pattern as the existing containsequals swap for hasMany relationships on line 248.

Also added integration tests covering equals and not_equals with array values for both hasMany and non-hasMany relationship fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant