fix: respect hidden: true for virtual fields that have reference to a relationship field (#12219)

Previously, `hidden: true` on a virtual field that references a
relationship field didn't work. Now, this field doesn't get calculated
if there's `hidden: true` and no `showHiddenFields` was passed.

Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
This commit is contained in:
Sasha
2025-05-15 23:48:08 +03:00
committed by GitHub
parent 88769c8244
commit 1f6efe9a46
5 changed files with 33 additions and 10 deletions

View File

@@ -2014,6 +2014,26 @@ describe('database', () => {
expect(doc.postTitle).toBe('my-title-10')
})
it('should respect hidden: true for virtual fields with reference', async () => {
const post = await payload.create({ collection: 'posts', data: { title: 'my-title-3' } })
const { id } = await payload.create({
collection: 'virtual-relations',
depth: 0,
data: { post: post.id },
})
const doc = await payload.findByID({ collection: 'virtual-relations', depth: 0, id })
expect(doc.postTitleHidden).toBeUndefined()
const doc_show = await payload.findByID({
collection: 'virtual-relations',
depth: 0,
id,
showHiddenFields: true,
})
expect(doc_show.postTitleHidden).toBe('my-title-3')
})
it('should allow virtual field as reference to ID', async () => {
const post = await payload.create({ collection: 'posts', data: { title: 'my-title' } })
const { id } = await payload.create({