payloadcms/payload · error · QueryError
The following path cannot be queried: ${relationOrPath}
Error message
The following path cannot be queried: ${relationOrPath} What it means
`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.
Source
Thrown at packages/drizzle/src/queries/parseParams.ts:224
let jsonQuerySelector = `${table[columnName].name}${jsonQuery}`
if (adapter.name === 'sqlite' && operator === 'not_like') {
jsonQuerySelector = `COALESCE(${table[columnName].name}${jsonQuery}, '')`
}
const rawSQLQuery = `${jsonQuerySelector} ${operatorKeys[operator].operator} ${formattedValue}`
constraints.push(sql.raw(rawSQLQuery))
break
}
if (getNotNullColumnByValue) {
const columnName = getNotNullColumnByValue(val)
if (columnName) {
constraints.push(isNotNull(table[columnName]))
} else {
throw new QueryError([{ path: relationOrPath }])
}
break
}
if (
operator === 'like' &&
(field.type === 'number' ||
field.type === 'relationship' ||
field.type === 'upload' ||
table[columnName].columnType === 'PgUUID')
) {
operator = 'equals'
}
if (operator === 'like') {
constraints.push(
and(
...val.split(' ').map((word) =>View on GitHub (pinned to 00c58b35c0)
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.
Example fix
// before: 'videos' is not in the relationship's relationTo list
await payload.find({ collection: 'x', where: { 'attach.relationTo': { equals: 'videos' } } })
// after: use an allowed relationTo, e.g. 'posts'
await payload.find({ collection: 'x', where: { 'attach.relationTo': { equals: 'posts' } } }) Defensive patterns
Strategy: validation
Validate before calling
// Validate relationTo against the relationship config
const rel = payload.collections[collection].config.flattenedFields[firstSeg]
const allowed = Array.isArray(rel?.relationTo) ? rel.relationTo : rel?.relationTo ? [rel.relationTo] : []
if (path.endsWith('.relationTo') && !allowed.includes(value)) {
throw new Error(`relationTo '${value}' not valid for '${firstSeg}'`)
} Type guard
const isAllowedRelationTo = (rel, value) => Array.isArray(rel?.relationTo) ? rel.relationTo.includes(value) : rel?.relationTo === value
Try / catch
try {
await payload.find({ collection, where })
} catch (err) {
if (err?.name === 'QueryError') {
return res.status(400).json({ error: 'This path cannot be queried with the given value.' })
}
throw err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Not supported
- Invalid ID value in ${JSON.stringify(queryValue)}
- Only 'equals' operator is supported for polymorphic relation
- The following path${results.length === 1 ? '' : 's'} cannot
- ${value} is not allowed as a JSON query value
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/337bda9b4dc0373f.
Report an issue: GitHub.