Skip to content

Query fails when filtering on two relationship fields that reference fields with the same name #15585

@leonardigabriele

Description

@leonardigabriele

Describe the Bug

When querying a collection with two different relationship fields that both have a nested field with the same name, the query fails. Each filter works correctly in isolation, but combining them causes an error.

Expected Behavior

The query should return documents where both conditions are satisfied.

Actual Behavior

The query fails. However:

  • Querying only artist.categories works
  • Querying only organizer.categories works
  • Renaming one of the categories fields to a unique name allows both filters to work together

Please fix this soon, it is impacting a project already in production.

Link to the code that reproduces this issue

https://github.com/leonardigabriele/query-test

Reproduction Steps

  1. Create two collections (e.g., artists and organizers) that both have a relationship field with the same name (e.g., categories)
  2. Create a third collection (e.g., events) with relationship fields to both artists and organizers
  3. Attempt to query filtering on both relationship paths:
const { docs } = await payload.find({
  collection: "events",
  where: {
    "artist.categories": {
      equals: 1,
    },
    "organizer.categories": {
      equals: 1,
    },
  },
});

Which area(s) are affected?

db: postgres

Environment Info

Binaries:
  Node: 24.13.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  payload: 3.76.0
  next: 16.1.6
  @payloadcms/db-postgres: 3.76.0
  @payloadcms/drizzle: 3.76.0
  @payloadcms/graphql: 3.76.0
  @payloadcms/next/utilities: 3.76.0
  @payloadcms/richtext-lexical: 3.76.0
  @payloadcms/translations: 3.76.0
  @payloadcms/ui/shared: 3.76.0
  react: 19.2.3
  react-dom: 19.2.3
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32510
  Available CPU cores: 20

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions