-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
defaultPopulate
property to collection config (#8934)
### What? Adds `defaultPopulate` property to collection config that allows to specify which fields to select when the collection is populated from another document. ```ts import type { CollectionConfig } from 'payload' // The TSlug generic can be passed to have type safety for `defaultPopulate`. // If avoided, the `defaultPopulate` type resolves to `SelectType`. export const Pages: CollectionConfig<'pages'> = { slug: 'pages', // I need only slug, NOT the WHOLE CONTENT! defaultPopulate: { slug: true, }, fields: [ { name: 'slug', type: 'text', required: true, }, ], } ``` ### Why? This is essential for example in case of links. You don't need the whole document, which can contain large data but only the `slug`. ### How? Implements `defaultPopulate` when populating relationships, including inside of lexical / slate rich text fields.
- Loading branch information
Showing
15 changed files
with
375 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import type { CollectionConfig } from 'payload' | ||
|
||
import { lexicalEditor, LinkFeature } from '@payloadcms/richtext-lexical' | ||
import { slateEditor } from '@payloadcms/richtext-slate' | ||
|
||
// The TSlug generic can be passed to have type safety for `defaultPopulate`. | ||
// If avoided, the `defaultPopulate` type resolves to `SelectType`. | ||
export const Pages: CollectionConfig<'pages'> = { | ||
slug: 'pages', | ||
// I need only slug, NOT the WHOLE CONTENT! | ||
defaultPopulate: { | ||
slug: true, | ||
}, | ||
fields: [ | ||
{ | ||
name: 'content', | ||
type: 'blocks', | ||
blocks: [ | ||
{ | ||
slug: 'cta', | ||
fields: [ | ||
{ | ||
name: 'title', | ||
type: 'text', | ||
required: true, | ||
}, | ||
{ | ||
name: 'link', | ||
type: 'group', | ||
fields: [ | ||
{ | ||
name: 'docPoly', | ||
type: 'relationship', | ||
relationTo: ['pages'], | ||
}, | ||
{ | ||
name: 'doc', | ||
type: 'relationship', | ||
relationTo: 'pages', | ||
}, | ||
{ | ||
name: 'docMany', | ||
hasMany: true, | ||
type: 'relationship', | ||
relationTo: 'pages', | ||
}, | ||
{ | ||
name: 'docHasManyPoly', | ||
type: 'relationship', | ||
relationTo: ['pages'], | ||
hasMany: true, | ||
}, | ||
{ | ||
name: 'label', | ||
type: 'text', | ||
required: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'richTextLexical', | ||
type: 'richText', | ||
editor: lexicalEditor({ | ||
features({ defaultFeatures }) { | ||
return [...defaultFeatures, LinkFeature({ enabledCollections: ['pages'] })] | ||
}, | ||
}), | ||
}, | ||
{ | ||
name: 'richTextSlate', | ||
type: 'richText', | ||
editor: slateEditor({}), | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'slug', | ||
type: 'text', | ||
required: true, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.