Skip to content

Select clause causes relationships in blocks fields to not populate #14157

@busbyk

Description

@busbyk

Describe the Bug

When querying a collection that contains a blocks field with relationship fields inside those blocks, using a select clause causes the relationships to be returned as empty arrays instead of being populated with the related documents.

Expected Behavior:
Relationships within blocks should be populated when using payload.find() with a select clause.

Actual Behavior:
Relationships within blocks are returned as empty arrays when a select clause is used, even though the relationships exist in the database and are correctly populated when no select clause is used.

This issue persists even when:

  • Setting explicit depth parameter
  • Using populate parameter to target the specific nested relationship path

Link to the code that reproduces this issue

https://github.com/busbyk/select-clause-population-behavior-reproduction

Reproduction Steps

  1. Clone the reproduction repository
  2. Install dependencies: pnpm install
  3. Copy environment variables: cp .env.example .env
  4. Generate types: pnpm run generate:types
  5. Run the integration tests: pnpm run test:int
  6. Observe the test output showing that:
    - WITHOUT select clause: layout[0].sponsors contains 3 populated sponsor objects ✅
    - WITH select clause: layout[0].sponsors is an empty array [] ❌
    - WITH select + depth: Still empty array ❌
    - WITH select + populate: Still empty array ❌

See tests/int/select-clause-bug.int.spec.ts for the full test suite demonstrating the bug.

Key code demonstrating the bug:
// This works - relationships are populated
const working = await payload.find({
collection: 'pages',
where: { id: { equals: pageId } }
})
// working.docs[0].layout[0].sponsors = [{ id: 1, name: "..." }, ...]

// This fails - relationships are empty
const broken = await payload.find({
collection: 'pages',
where: { id: { equals: pageId } },
select: { id: true, layout: true }
})
// broken.docs[0].layout[0].sponsors = []

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

area: core

Environment Info

Binaries:
  Node: 22.14.0
  npm: 11.2.0
  Yarn: N/A
  pnpm: 10.14.0
Relevant Packages:
  payload: 3.59.1
  next: 15.4.4
  @payloadcms/db-sqlite: 3.59.1
  @payloadcms/drizzle: 3.59.1
  @payloadcms/email-nodemailer: 3.59.1
  @payloadcms/graphql: 3.59.1
  @payloadcms/next/utilities: 3.59.1
  @payloadcms/payload-cloud: 3.59.1
  @payloadcms/richtext-lexical: 3.59.1
  @payloadcms/translations: 3.59.1
  @payloadcms/ui/shared: 3.59.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:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 14

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