Files
payload/test/fields/collections/Relationship/index.ts

60 lines
1.3 KiB
TypeScript

import type { CollectionConfig } from '../../../../src/collections/config/types';
export const relationshipFieldsSlug = 'relationship-fields';
const RelationshipFields: CollectionConfig = {
slug: relationshipFieldsSlug,
fields: [
{
name: 'relationship',
type: 'relationship',
relationTo: ['text-fields', 'array-fields'],
required: true,
},
{
name: 'relationToSelf',
type: 'relationship',
relationTo: relationshipFieldsSlug,
},
{
name: 'relationToSelfSelectOnly',
type: 'relationship',
relationTo: relationshipFieldsSlug,
admin: {
allowCreate: false,
},
},
{
name: 'relationWithDynamicDefault',
type: 'relationship',
relationTo: 'users',
defaultValue: ({ user }) => user.id,
},
{
name: 'relationHasManyWithDynamicDefault',
type: 'relationship',
relationTo: ['users'],
defaultValue: ({ user }) => ({
relationTo: 'users',
value: user.id,
}),
},
{
name: 'relationshipWithMin',
type: 'relationship',
relationTo: 'text-fields',
hasMany: true,
min: 2,
},
{
name: 'relationshipWithMax',
type: 'relationship',
relationTo: 'text-fields',
hasMany: true,
max: 2,
},
],
};
export default RelationshipFields;