diff --git a/packages/plugins/workflow/src/server/__tests__/triggers/collection.test.ts b/packages/plugins/workflow/src/server/__tests__/triggers/collection.test.ts index 87e10543b..8da49c16c 100644 --- a/packages/plugins/workflow/src/server/__tests__/triggers/collection.test.ts +++ b/packages/plugins/workflow/src/server/__tests__/triggers/collection.test.ts @@ -204,6 +204,35 @@ describe('workflow > triggers > collection', () => { expect(job.result.data.category.title).toBe('c1'); }); + it('appends belongsTo null', async () => { + const workflow = await WorkflowModel.create({ + enabled: true, + type: 'collection', + config: { + mode: 1, + collection: 'posts', + appends: ['category'] + } + }); + + await workflow.createNode({ + type: 'echo' + }); + + const post = await PostRepo.create({ + values: { + title: 't1', + } + }); + + await sleep(500); + + const [execution] = await workflow.getExecutions(); + expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED); + const [job] = await execution.getJobs(); + expect(job.result.data.category).toBeNull(); + }); + it('appends hasMany', async () => { const workflow = await WorkflowModel.create({ enabled: true, diff --git a/packages/plugins/workflow/src/server/triggers/collection.ts b/packages/plugins/workflow/src/server/triggers/collection.ts index f4d22dc39..9c40ce77e 100644 --- a/packages/plugins/workflow/src/server/triggers/collection.ts +++ b/packages/plugins/workflow/src/server/triggers/collection.ts @@ -79,7 +79,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M }); includeFields.forEach(field => { const value = included!.get(field); - data.set(field, Array.isArray(value) ? value.map(item => item.toJSON()) : value.toJSON(), { raw: true }); + data.set(field, Array.isArray(value) ? value.map(item => item.toJSON()) : (value ? value.toJSON() : null), { raw: true }); }); }