Any field in Payload can be marked virtual. The best version is virtual as a path — it automatically resolves the value from a relationship, with nothing written to the database:
{
name: 'authorName',
type: 'text',
virtual: 'author.name', // walks through the `author` relationship down to `name`
}
And when the path crosses a hasMany relationship, you get an array back:
{
name: 'categoryTitles',
type: 'text',
hasMany: true,
virtual: 'categories.title', // => ['Tech', 'News', 'Updates']
}
The field shows up in your API responses and in your generated types — but it never takes up a column. Perfect for flattening relationship data without denormalizing your schema.
Top comments (0)