payloadcms / payloadcms/payload

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

Open
#15,909 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: core created-by: Contributor status: needs-triage
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the failing path named in @payloadcms/drizzle/dist/queries/getTableColumnFromPath.js and reproduce the REST request from the issue using the linked minimal app. Compare the exists and polymorphic equals cases for the hasMany authors field; done means both REST and admin list filters return the matching article instead of APIError: Not supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, typescript
Domain
api, backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.