Polymorphic Join field is broken
Describe the Bug
According to the documentation, we should be able to create a polymorphic join field like for example:
export const People: CollectionConfig = {
slug: 'people',
fields: [
{
name: 'name',
type: 'text',
required: true,
},
{
name: 'roles',
type: 'join',
collection: ['staff-roles', 'student-roles'],
on: 'person',
},
],
}
When opening the edit page of the People collection in the Admin, we:
- Get an error in the server console
- The edit page loads, but the join field is not rendered completely. No joined rows are shown.
The issue happens on as early as 3.43, but also on 3.55.1 and main.
This is the error we get in the console:
[16:08:10] ERROR: There was an error building form state
err: {
"type": "TypeError",
"message": "Cannot read properties of undefined (reading 'admin')",
"stack":
TypeError: Cannot read properties of undefined (reading 'admin')
at getColumns (/home/robin/code/payload/.next/server/chunks/ssr/packages_ui_src_e487b3c2._.js:5190:465)
at buildTableState (/home/robin/code/payload/.next/server/chunks/ssr/packages_ui_src_e487b3c2._.js:6074:181)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async buildTableStateHandler (/home/robin/code/payload/.next/server/chunks/ssr/packages_ui_src_e487b3c2._.js:5938:21)
at async executeActionAndPrepareForRender (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js:33:4432)
at async /home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js:33:2264
at async handleAction (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js:32:23711)
at async renderToHTMLOrFlightImpl (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js:38:30115)
at async doRender (/home/robin/code/payload/.next/server/chunks/ssr/905b1_next_dist_650a1e83._.js:2520:28)
at async AppPageRouteModule.handleResponse (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js:40:57864)
at async handleResponse (/home/robin/code/payload/.next/server/chunks/ssr/905b1_next_dist_650a1e83._.js:2666:32)
at async handler (/home/robin/code/payload/.next/server/chunks/ssr/905b1_next_dist_650a1e83._.js:3043:20)
at async doRender (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/base-server.js:1586:34)
at async DevServer.renderToResponseWithComponentsImpl (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/base-server.js:1928:13)
at async DevServer.renderPageComponent (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/base-server.js:2394:24)
at async DevServer.renderToResponseImpl (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/base-server.js:2434:32)
at async DevServer.pipeImpl (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/base-server.js:1034:25)
at async NextNodeServer.handleCatchallRenderRequest (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/next-server.js:393:17)
at async DevServer.handleRequestImpl (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/base-server.js:925:17)
at async /home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/dev/next-dev-server.js:398:20
at async Span.traceAsyncFn (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/trace/trace.js:157:20)
at async DevServer.handleRequest (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/dev/next-dev-server.js:394:24)
at async invokeRender (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/lib/router-server.js:239:21)
at async handleRequest (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/lib/router-server.js:436:24)
at async NextCustomServer.requestHandlerImpl (/home/robin/code/payload/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_babel-_nh6e7yzpetogfn6s3qd7kk6wqu/node_modules/next/dist/server/lib/router-server.js:464:13)
at async Server.<anonymous> (file:///home/robin/code/payload/test/dev.ts:1:2992)
}
The response we get in the API works, except the roles field will also be empty.
I initially came across this issue when using Postgres, but the issue also exists when using Mongo as reproduced in the linked repository.
Link to the code that reproduces this issue
https://github.com/RobinvdGriend/payload/tree/issue/polymorphic-join
Reproduction Steps
This issue has been reproduced following ISSUE_GUIDE.md. After cloning the repository, install the packages:
pnpm install
The code to reproduce the issue can be found under test/_community. To start the dev server run:
pnpm dev _community --start-memory-db
Navigate to (http://localhost:3000/admin/collections/people). You should see a single item in the index. Click this item to go to its edit page, this reproduces the issue. You see the roles field remains empty and an error is reported in the server console. Verify that indeed this person has roles by navigating to the 'Staff Roles' and 'Student Roles' collections.
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
Binaries:
Node: 22.16.0
npm: 11.4.2
Yarn: N/A
pnpm: 10.15.1
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Thu, 28 Aug 2025 19:49:53 +0000
Available memory (MB): 15352
Available CPU cores: 6
For me, the following error is thrown when calling payload.find() on a collection with a polymorphic join field:
TypeError: operatorMap[payloadOperator] is not a function
at buildSQLWhere (file:///Users/driescruyskens/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._08d10a1d1bc00a5a90fa57ef86917fcf/node_modules/@payloadcms/drizzle/dist/find/traverseFields.js:60:48)
at buildSQLWhere (file:///Users/driescruyskens/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._08d10a1d1bc00a5a90fa57ef86917fcf/node_modules/@payloadcms/drizzle/dist/find/traverseFields.js:43:38)
at file:///Users/driescruyskens/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._08d10a1d1bc00a5a90fa57ef86917fcf/node_modules/@payloadcms/drizzle/dist/find/traverseFields.js:399:54
at Array.forEach (<anonymous>)
at traverseFields (file:///Users/driescruyskens/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._08d10a1d1bc00a5a90fa57ef86917fcf/node_modules/@payloadcms/drizzle/dist/find/traverseFields.js:65:12)
at buildFindManyArgs (file:///Users/driescruyskens/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._08d10a1d1bc00a5a90fa57ef86917fcf/node_modules/@payloadcms/drizzle/dist/find/buildFindManyArgs.js:30:5)
at find (file:///Users/driescruyskens/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._08d10a1d1bc00a5a90fa57ef86917fcf/node_modules/@payloadcms/drizzle/dist/find/findMany.js:31:26)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
sources collection:
{
name: "usedIn",
type: "join",
collection: ["entries"],
on: "sourcedFrom",
},
entries collection:
{
name: "sourcedFrom",
type: "relationship",
relationTo: "sources",
hasMany: false,
},
The issue is also present if the join's collection property is an array with a single value:
collection: ["entries"]
Full error I encountered message
TypeError: operatorMap[payloadOperator] is not a function
at buildSQLWhere (file:///Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._569e8cb0977bcf09cf495fe1fa2fe98d/node_modules/@payloadcms/drizzle/dist/find/traverseFields.js:60:48)
at buildSQLWhere (file:///Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._569e8cb0977bcf09cf495fe1fa2fe98d/node_modules/@payloadcms/drizzle/dist/find/traverseFields.js:43:38)
at file:///Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._569e8cb0977bcf09cf495fe1fa2fe98d/node_modules/@payloadcms/drizzle/dist/find/traverseFields.js:399:54
at Array.forEach (<anonymous>)
at traverseFields (file:///Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._569e8cb0977bcf09cf495fe1fa2fe98d/node_modules/@payloadcms/drizzle/dist/find/traverseFields.js:65:12)
at buildFindManyArgs (file:///Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._569e8cb0977bcf09cf495fe1fa2fe98d/node_modules/@payloadcms/drizzle/dist/find/buildFindManyArgs.js:30:5)
at find (file:///Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._569e8cb0977bcf09cf495fe1fa2fe98d/node_modules/@payloadcms/drizzle/dist/find/findMany.js:30:26)
at Object.find (file:///Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._569e8cb0977bcf09cf495fe1fa2fe98d/node_modules/@payloadcms/drizzle/dist/find.js:7:12)
at findOperation (file:///Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/payload/dist/collections/operations/find.js:131:39)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.handler (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/src_lib_4e7f508d._.js:2260:24)
at async next (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11194:14)
at async next (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11188:33)
at async /Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/src_a2b4ceca._.js:955:16
at async /Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11182:28
at async next (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11176:30)
at async next (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11188:33)
at async /Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11182:28
at async next (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11176:30)
at async next (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11188:33)
at async /Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11182:28
at async next (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11176:30)
at async /Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:11083:28
at async /Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:12958:40
at async /Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:12925:28
at async /Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:13481:28
at async handleRequest (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/[root-of-the-server]__a27203e4._.js:98:26)
at async AppRouteRouteModule.do (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:37789)
at async AppRouteRouteModule.handle (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:45045)
at async responseGenerator (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:16204:38)
at async AppRouteRouteModule.handleResponse (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:1:187851)
at async handleResponse (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:16266:32)
at async handler (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/.next/dev/server/chunks/node_modules__pnpm_dd72b8a0._.js:16319:13)
at async DevServer.renderToResponseWithComponentsImpl (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/base-server.js:1413:9)
at async DevServer.renderPageComponent (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/base-server.js:1465:24)
at async DevServer.renderToResponseImpl (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/base-server.js:1515:32)
at async DevServer.pipeImpl (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/base-server.js:1021:25)
at async NextNodeServer.handleCatchallRenderRequest (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/next-server.js:394:17)
at async DevServer.handleRequestImpl (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/base-server.js:912:17)
at async /Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/dev/next-dev-server.js:382:20
at async Span.traceAsyncFn (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/trace/trace.js:157:20)
at async DevServer.handleRequest (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/dev/next-dev-server.js:378:24)
at async invokeRender (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/lib/router-server.js:240:21)
at async handleRequest (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/lib/router-server.js:436:24)
at async requestHandlerImpl (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/lib/router-server.js:484:13)
at async Server.requestListener (/Users/<myname>/Work/tryouts/payload-vercel-tryout/nextjs/node_modules/.pnpm/[email protected]_@[email protected][email protected]_babel-plugin-react-compiler@19_5d7e1ff6ae86c1734ea06f625a244811/node_modules/next/dist/server/lib/start-server.js:226:13)
Has the same issue: error: syntax error at or near "as"