diff --git a/packages/core/actions/src/__tests__/create-action.test.ts b/packages/core/actions/src/__tests__/create-action.test.ts index 43e8b7491..6b50bf696 100644 --- a/packages/core/actions/src/__tests__/create-action.test.ts +++ b/packages/core/actions/src/__tests__/create-action.test.ts @@ -108,4 +108,13 @@ describe('create action', () => { expect(await tag.hasPost(p1)).toBeTruthy(); expect(tag.get('name')).toEqual('hello'); }); + + test('create with empty values', async () => { + const response = await app.agent().resource('posts').create({}); + expect(response.statusCode).toEqual(200); + const p1 = await Post.repository.findOne(); + + const response2 = await app.agent().resource('posts.comments', p1.get('id')).create({}); + expect(response2.statusCode).toEqual(200); + }); }); diff --git a/packages/core/database/src/update-guard.ts b/packages/core/database/src/update-guard.ts index 122c93b97..a8603758e 100644 --- a/packages/core/database/src/update-guard.ts +++ b/packages/core/database/src/update-guard.ts @@ -2,7 +2,6 @@ import lodash from 'lodash'; import { ModelStatic } from 'sequelize'; import { Model } from './model'; import { AssociationKeysToBeUpdate, BlackList, WhiteList } from './repository'; -import { isPlainObject } from '@nocobase/utils/src'; type UpdateValueItem = string | number | UpdateValues; @@ -100,6 +99,10 @@ export class UpdateGuard { * @param values */ sanitize(values: UpdateValues) { + if (values === null || values === undefined) { + return values; + } + values = lodash.clone(values); if (!this.model) {