In Payload v3, forceSelect was a static object that deep-merged with the caller's select. In v4 it became a function — and that function replaces the caller's select instead of adding to it:
export const Posts: CollectionConfig = {
slug: 'posts',
// Careful: you must spread the caller's select yourself, or you'll overwrite it!
select: ({ operation, req, select }) =>
select ? { ...select, title: true } : undefined,
fields: [/* ... */],
}
Returning undefined means "leave the caller's select untouched." You also get operation and req, so you can hand back a different select for the REST API than for the admin panel.
One important detail: there's no document data here — select runs before read.
Top comments (0)