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:
@@ -466,6 +466,12 @@ export default buildConfigWithDefaults({
|
||||
type: 'text',
|
||||
virtual: 'post.title',
|
||||
},
|
||||
{
|
||||
name: 'postTitleHidden',
|
||||
type: 'text',
|
||||
virtual: 'post.title',
|
||||
hidden: true,
|
||||
},
|
||||
{
|
||||
name: 'postCategoryTitle',
|
||||
type: 'text',
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -374,6 +374,7 @@ export interface Place {
|
||||
export interface VirtualRelation {
|
||||
id: string;
|
||||
postTitle?: string | null;
|
||||
postTitleHidden?: string | null;
|
||||
postCategoryTitle?: string | null;
|
||||
postCategoryID?:
|
||||
| {
|
||||
@@ -828,6 +829,7 @@ export interface PlacesSelect<T extends boolean = true> {
|
||||
*/
|
||||
export interface VirtualRelationsSelect<T extends boolean = true> {
|
||||
postTitle?: T;
|
||||
postTitleHidden?: T;
|
||||
postCategoryTitle?: T;
|
||||
postCategoryID?: T;
|
||||
postID?: T;
|
||||
|
||||
Reference in New Issue
Block a user