Skip to content

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

Merged
PatrikKozak merged 6 commits intopayloadcms:mainfrom
maximseshuk:fix/sanitize-query-value-array
Apr 8, 2026
Merged

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

Conversation

@maximseshuk
Copy link
Copy Markdown
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.

@PatrikKozak PatrikKozak self-assigned this Apr 2, 2026
@PatrikKozak PatrikKozak merged commit 59af156 into payloadcms:main Apr 8, 2026
467 of 471 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

🚀 This is included in version v3.82.0

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.

4 participants