{"record":{"id":"337bda9b4dc0373f","repo":"payloadcms/payload","slug":"the-following-path-cannot-be-queried-relationor","errorCode":null,"errorMessage":"The following path cannot be queried: ${relationOrPath}","messagePattern":"The following path cannot be queried: (.+?)","errorType":"validation","errorClass":"QueryError","httpStatus":400,"severity":"error","filePath":"packages/drizzle/src/queries/parseParams.ts","lineNumber":224,"sourceCode":"                  let jsonQuerySelector = `${table[columnName].name}${jsonQuery}`\n\n                  if (adapter.name === 'sqlite' && operator === 'not_like') {\n                    jsonQuerySelector = `COALESCE(${table[columnName].name}${jsonQuery}, '')`\n                  }\n\n                  const rawSQLQuery = `${jsonQuerySelector} ${operatorKeys[operator].operator} ${formattedValue}`\n\n                  constraints.push(sql.raw(rawSQLQuery))\n\n                  break\n                }\n\n                if (getNotNullColumnByValue) {\n                  const columnName = getNotNullColumnByValue(val)\n                  if (columnName) {\n                    constraints.push(isNotNull(table[columnName]))\n                  } else {\n                    throw new QueryError([{ path: relationOrPath }])\n                  }\n                  break\n                }\n\n                if (\n                  operator === 'like' &&\n                  (field.type === 'number' ||\n                    field.type === 'relationship' ||\n                    field.type === 'upload' ||\n                    table[columnName].columnType === 'PgUUID')\n                ) {\n                  operator = 'equals'\n                }\n\n                if (operator === 'like') {\n                  constraints.push(\n                    and(\n                      ...val.split(' ').map((word) =>","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/drizzle/src/queries/parseParams.ts#L206-L242","documentation":"`QueryError` from `parseParams`: when resolving a relationship-by-value path, the adapter uses `getNotNullColumnByValue` to map the supplied value to a concrete column (e.g. picking the right `<collection>_id` column for a polymorphic relationship's `relationTo`). If that function returns `undefined` (no column matches the value), the path cannot be queried and the adapter raises a `QueryError` carrying the offending path.","triggerScenarios":"Querying a polymorphic relationship by a value/relationTo that is not one of the relationship's configured `relationTo` collections, so no `<collection>ID` column matches. For example `where: { 'link.relationTo': { equals: 'unknownSlug' } }` where `unknownSlug` is not an allowed relationTo.","commonSituations":"Client sends a relationTo slug that isn't valid for the field; collection was removed from the relationship's `relationTo` array but stale queries remain; querying relationship values with data shapes the resolver can't map to a column.","solutions":["Ensure the value used for the relationship path corresponds to one of the field's allowed `relationTo` collections (or a valid ID).","Validate user-supplied relationTo slugs against the field config before issuing the query.","Restructure the query to filter the relationship by `id`/`relationTo` columns directly rather than by an unmappable value."],"exampleFix":"// before: 'videos' is not in the relationship's relationTo list\nawait payload.find({ collection: 'x', where: { 'attach.relationTo': { equals: 'videos' } } })\n// after: use an allowed relationTo, e.g. 'posts'\nawait payload.find({ collection: 'x', where: { 'attach.relationTo': { equals: 'posts' } } })","handlingStrategy":"validation","validationCode":"// Validate relationTo against the relationship config\nconst rel = payload.collections[collection].config.flattenedFields[firstSeg]\nconst allowed = Array.isArray(rel?.relationTo) ? rel.relationTo : rel?.relationTo ? [rel.relationTo] : []\nif (path.endsWith('.relationTo') && !allowed.includes(value)) {\n  throw new Error(`relationTo '${value}' not valid for '${firstSeg}'`)\n}","typeGuard":"const isAllowedRelationTo = (rel, value) =>\n  Array.isArray(rel?.relationTo) ? rel.relationTo.includes(value) : rel?.relationTo === value","tryCatchPattern":"try {\n  await payload.find({ collection, where })\n} catch (err) {\n  if (err?.name === 'QueryError') {\n    return res.status(400).json({ error: 'This path cannot be queried with the given value.' })\n  }\n  throw err\n}","preventionTips":["Validate relationTo slugs against the field config before querying.","Remove stale queries after changing a relationship's relationTo list.","Filter relationships by id/relationTo columns when value-shape queries fail."],"tags":["query","relationships","polymorphic","where","validation"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}