Skip to content

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

@atimmer

Description

@atimmer

Describe the bug

Filtering a polymorphic relationship field with hasMany: true throws APIError: Not supported.

I can reproduce this in a fresh Payload app with a minimal schema:

  • users
  • persons
  • partners
  • articles
    • title: text
    • authors: relationship, relationTo: ['persons', 'partners'], hasMany: true

This affects:

  • REST queries like where[authors][exists]=true
  • Admin list view filters generated by the UI, including:
    • exists
    • polymorphic equals object notation

Reproduction repo

https://github.com/atimmer/payload-polymorphic-hasmany-filter-repro

Versions

  • payload: 3.79.0
  • @payloadcms/db-postgres: 3.79.0
  • PostgreSQL 16

Minimal field config

{
  name: 'authors',
  type: 'relationship',
  relationTo: ['persons', 'partners'],
  hasMany: true,
}

### Link to the code that reproduces this issue

https://github.com/atimmer/payload-polymorphic-hasmany-filter-repro

### Reproduction Steps

## REST reproduction

This request returns `500` instead of returning the matching article:

```bash
curl -i 'http://127.0.0.1:3110/api/articles?where%5Bauthors%5D%5Bexists%5D=true'

Expected: one article.

Actual: 500 Internal Server Error with APIError: Not supported.

Admin reproduction

  1. Log in:

    curl -s -c /tmp/payload-repro-cookies.txt \
      -H 'Content-Type: application/json' \
      -d '{"email":"admin@example.com","password":"password"}' \
      http://127.0.0.1:3110/api/users/login
  2. Request the admin list page using the exists filter generated by the admin UI:

    curl -i -b /tmp/payload-repro-cookies.txt \
      'http://127.0.0.1:3110/admin/collections/articles?depth=1&limit=10&where%5Bor%5D%5B0%5D%5Band%5D%5B0%5D%5Bauthors%5D%5Bexists%5D=true&page=1'
  3. Request the admin list page using the equals filter generated by the admin UI:

    curl -i -b /tmp/payload-repro-cookies.txt \
      'http://127.0.0.1:3110/admin/collections/articles?depth=1&limit=10&where%5Bor%5D%5B0%5D%5Band%5D%5B0%5D%5Bauthors%5D%5Bequals%5D%5B0%5D%5BrelationTo%5D=persons&where%5Bor%5D%5B0%5D%5Band%5D%5B0%5D%5Bauthors%5D%5Bequals%5D%5B0%5D%5Bvalue%5D=1&page=1'

Expected: the list view loads and shows the matching article.

Actual: the server logs APIError: Not supported from @payloadcms/drizzle/dist/queries/getTableColumnFromPath.js.

Which area(s) are affected?

area: core

Environment Info

Node 25.4.0
npm 11.7.0
pnpm 10.17.0
payload 3.79.0
@payloadcms/db-postgres 3.79.0
@payloadcms/drizzle 3.79.0
next 15.4.11
react / react-dom 19.2.1
OS: macOS Darwin arm64, 16 cores, 64 GB RAM

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions