Skip to content

"or" filters on localized relationship fields only return matches for a single locale #14527

@matteocollina

Description

@matteocollina

Describe the Bug

I have a collection Documents with a 1-N relationship to Revisions.

The field revisions.name is localized with two locales (e.g., it and en).

  • Filtering documents that have revisions in locale A works ✅
  • Filtering documents that have revisions in locale B works ✅

But combining both conditions with or only returns documents that match one of the locales (seemingly the default) ❌

It looks like and/or filters don’t behave correctly when applied to localized subfields inside related documents.

Link to the code that reproduces this issue

https://dev.daygbk4qgwfks.amplifyapp.com/api/documents

Reproduction Steps

Example response (GET /documents)

{
  "docs": [
    {   // Document with only locale B revision
      "id": 1,
      "revisions": {
        "docs": [
          {
            "id": 11,
            "name": { "en": "Revision one" }
          }
        ]
      }
    },
    {   // Document with both locales
      "id": 2,
      "revisions": {
        "docs": [
          {
            "id": 12,
            "name": { "it": "Revisione due", "en": "Revision two" }
          }
        ]
      }
    },
    {   // Document with only locale A revision
      "id": 3,
      "revisions": {
        "docs": [
          {
            "id": 14,
            "name": { "it": "Revisione tre" }
          }
        ]
      }
    }
  ]
}

✅ Working queries

  • Only locale A (example it):
{
  "and": [
    { "status": { "equals": "distributed" } },
    { "revisions.name.it": { "exists": true } }
  ]
}

✅ Working queries

  • Only locale B (example en):
{
  "and": [
    { "status": { "equals": "distributed" } },
    { "revisions.name.en": { "exists": true } }
  ]
}

❌ Failing query (unexpected result)

{
  "and": [
    { "status": { "equals": "distributed" } },
    {
      "or": [
        { "revisions.name.it": { "exists": true } },
        { "revisions.name.en": { "exists": true } }
      ]
    }
  ]
}

Which area(s) are affected? (Select all that apply)

Not sure

Environment Info

Binaries:
  Node: 20.18.3
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: 10.13.1
Relevant Packages:
  payload: 3.49.1
  next: 15.3.0
  @payloadcms/db-mongodb: 3.49.1
  @payloadcms/db-postgres: 3.49.1
  @payloadcms/email-nodemailer: 3.49.1
  @payloadcms/graphql: 3.49.1
  @payloadcms/live-preview: 3.49.1
  @payloadcms/live-preview-react: 3.49.1
  @payloadcms/next/utilities: 3.49.1
  @payloadcms/payload-cloud: 3.49.1
  @payloadcms/plugin-cloud-storage: 3.49.1
  @payloadcms/plugin-form-builder: 3.49.1
  @payloadcms/plugin-nested-docs: 3.49.1
  @payloadcms/plugin-redirects: 3.49.1
  @payloadcms/plugin-search: 3.49.1
  @payloadcms/plugin-seo: 3.49.1
  @payloadcms/richtext-lexical: 3.49.1
  @payloadcms/storage-s3: 3.49.1
  @payloadcms/translations: 3.49.1
  @payloadcms/ui/shared: 3.49.1
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:30 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 12

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs-triagePossible bug which hasn't been reproduced yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions