Continuation of https://github.com/payloadcms/payload/pull/12265. Currently, using `select` on new relationship virtual fields: ``` const doc = await payload.findByID({ collection: 'virtual-relations', depth: 0, id, select: { postTitle: true }, }) ``` doesn't work, because in order to calculate `post.title`, the `post` field must be selected as well. This PR adds logic that sanitizes the incoming `select` to include those relationships into `select` (that are related to selected virtual fields) --------- Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
131 lines
2.2 KiB
TypeScript
131 lines
2.2 KiB
TypeScript
import type { CollectionConfig } from 'payload'
|
|
|
|
import { pagesSlug } from '../shared.js'
|
|
|
|
export const Pages: CollectionConfig = {
|
|
slug: pagesSlug,
|
|
labels: {
|
|
singular: 'Page',
|
|
plural: 'Pages',
|
|
},
|
|
admin: {
|
|
useAsTitle: 'title',
|
|
},
|
|
versions: {
|
|
drafts: true,
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'title',
|
|
label: { en: 'Title', es: 'Título', de: 'Titel' },
|
|
type: 'text',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'localized',
|
|
type: 'text',
|
|
localized: true,
|
|
},
|
|
{
|
|
name: 'group',
|
|
type: 'group',
|
|
fields: [
|
|
{
|
|
name: 'value',
|
|
type: 'text',
|
|
defaultValue: 'group value',
|
|
},
|
|
{
|
|
name: 'ignore',
|
|
type: 'text',
|
|
},
|
|
{
|
|
name: 'array',
|
|
type: 'array',
|
|
fields: [
|
|
{
|
|
name: 'field1',
|
|
type: 'text',
|
|
},
|
|
{
|
|
name: 'field2',
|
|
type: 'text',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'array',
|
|
type: 'array',
|
|
fields: [
|
|
{
|
|
name: 'field1',
|
|
type: 'text',
|
|
},
|
|
{
|
|
name: 'field2',
|
|
type: 'text',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'blocks',
|
|
type: 'blocks',
|
|
blocks: [
|
|
{
|
|
slug: 'hero',
|
|
fields: [
|
|
{
|
|
name: 'title',
|
|
type: 'text',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
slug: 'content',
|
|
fields: [
|
|
{
|
|
name: 'richText',
|
|
type: 'richText',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'author',
|
|
type: 'relationship',
|
|
relationTo: 'users',
|
|
},
|
|
{
|
|
name: 'virtualRelationship',
|
|
type: 'text',
|
|
virtual: 'author.name',
|
|
},
|
|
{
|
|
name: 'virtual',
|
|
type: 'text',
|
|
virtual: true,
|
|
hooks: {
|
|
afterRead: [() => 'virtual value'],
|
|
},
|
|
},
|
|
{
|
|
name: 'hasManyNumber',
|
|
type: 'number',
|
|
hasMany: true,
|
|
},
|
|
{
|
|
name: 'relationship',
|
|
type: 'relationship',
|
|
relationTo: 'users',
|
|
},
|
|
{
|
|
name: 'excerpt',
|
|
label: 'Excerpt',
|
|
type: 'text',
|
|
},
|
|
],
|
|
}
|