Skip to content

fix(drizzle): support filtering polymorphic hasMany relationship fields#15913

Open
naaa760 wants to merge 2 commits intopayloadcms:mainfrom
naaa760:fix/filt-hasmny-relnt-thr
Open

fix(drizzle): support filtering polymorphic hasMany relationship fields#15913
naaa760 wants to merge 2 commits intopayloadcms:mainfrom
naaa760:fix/filt-hasmny-relnt-thr

Conversation

@naaa760
Copy link
Contributor

@naaa760 naaa760 commented Mar 11, 2026

what?

  • Support filtering polymorphic hasMany relationship fields in REST and the admin list view.

Why?

  • Filtering on polymorphic hasMany fields (e.g. where[authors][exists]=true or polymorphic equals) caused APIError: Not supported because the path resolution logic didn’t handle these cases.

How?

  • In getTableColumnFromPath.ts: handle the exists filter by returning the relationship table’s parent column, and support polymorphic equals when the value is an array (e.g. from the admin UI).
  • In sanitizeQueryValue.ts: normalize polymorphic values when they come as a single-element array so the equals logic works correctly.

Fixes #15909

Copy link
Member

@r1tsuu r1tsuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This definitely needs an integration test, I'd put this to test/relationships/int.spec.ts

@atimmer
Copy link
Contributor

atimmer commented Mar 11, 2026

This fixes the issue when filtering for specific authors and also when filtering for 'has an author' or 'doesn't have an author'.

There is one specific case where it still errors. When I try to filter for authors value "Nothing" I get an error:

## Error Type
Runtime TypeError

## Error Message
Cannot destructure property 'hasMany' of 'n' as it is undefined.

Next.js version: 15.5.9 (Webpack)

Basically this URL: http://localhost:3105/admin/collections/articles?depth=1&limit=10&where%5Bor%5D%5B0%5D%5Band%5D%5B0%5D%5Bauthors%5D%5Bequals%5D%5B0%5D%5Bvalue%5D=null&page=1

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.

Filtering polymorphic hasMany relationship throws APIError: Not supported in admin and REST

3 participants