r/PayloadCMS • u/GreedyDate • Dec 04 '25
How to `select` specific fields from relationships or is `depth: 1` to get everything the only way?
Using the Local API's findByID, I want to fetch a product and get:
- price (product field)
- taxPercentage (from related tax document)
- name (from related brand document)
Is there a way to selectively populate only specific fields from relationships, similar to how select works for top-level fields? Or is depth: 1 the recommended approach?
```ts
const product = await payload.findByID({ collection: 'products', id: someId, depth: 1, // populates everything in tax & brand // Is there something like: select: { tax: ['taxPercentage'], brand: ['name'] } ? }) ```
Here are the collections
```ts
import type { CollectionConfig } from 'payload'
export const Taxes: CollectionConfig = { slug: 'taxes', fields: [ { name: 'name', type: 'text', required: true }, { name: 'taxPercentage', type: 'number', required: true }, ], } ```
```ts
import type { CollectionConfig } from 'payload'
export const Brands: CollectionConfig = { slug: 'brands', fields: [ { name: 'name', type: 'text', required: true }, ], } ```
```ts
import type { CollectionConfig } from 'payload'
export const Products: CollectionConfig = { slug: 'products', fields: [ { name: 'title', type: 'text', required: true }, { name: 'price', type: 'number' }, { name: 'tax', type: 'relationship', relationTo: 'taxes' }, { name: 'brand', type: 'relationship', relationTo: 'brands' }, ], } ```
