From d77b4aa36d0026b37dde7c36f5b13f760d96af70 Mon Sep 17 00:00:00 2001 From: Katherine Date: Fri, 29 Nov 2024 22:39:20 +0800 Subject: [PATCH 1/2] refactor: set small as table default size (#5755) --- .../modules/blocks/data-blocks/table/tableBlockSettings.tsx | 2 +- .../src/schema-component/antd/association-field/SubTable.tsx | 3 +-- .../core/client/src/schema-component/antd/table-v2/Table.tsx | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx b/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx index a3f4bbecae..da441e8f62 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx @@ -202,7 +202,7 @@ export const tableBlockSettings = new SchemaSettings({ }, null); return { title: t('Table size'), - value: schema?.['x-component-props']?.size || 'middle', + value: schema?.['x-component-props']?.size || 'small', options: [ { label: t('Large'), value: 'large' }, { label: t('Middle'), value: 'middle' }, diff --git a/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx b/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx index f77bcc1dd1..368cb8e461 100644 --- a/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx @@ -64,7 +64,7 @@ const subTableContainer = css` `; const tableClassName = css` - .ant-formily-item.ant-formily-item-feedback-layout-loose { + .ant-formily-item-feedback-layout-popover { margin-bottom: 0px !important; } .ant-formily-editable { @@ -201,7 +201,6 @@ export const SubTable: any = observer( Date: Sat, 30 Nov 2024 08:59:07 +0800 Subject: [PATCH 2/2] fix: update association with foreign key (#5756) --- .../src/__tests__/update-associations.test.ts | 42 +++++++++++++++++++ .../core/database/src/update-associations.ts | 10 ++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/packages/core/database/src/__tests__/update-associations.test.ts b/packages/core/database/src/__tests__/update-associations.test.ts index e20e8ef602..cd458586b3 100644 --- a/packages/core/database/src/__tests__/update-associations.test.ts +++ b/packages/core/database/src/__tests__/update-associations.test.ts @@ -66,6 +66,48 @@ describe('update associations', () => { expect(profile1['userId']).toBe(user.id); }); + it('should update has many association with foreign key', async () => { + const User = db.collection({ + name: 'users', + fields: [ + { type: 'string', name: 'name' }, + { type: 'hasMany', name: 'profiles', foreignKey: 'userId', target: 'profiles' }, + ], + }); + + const Profile = db.collection({ + name: 'profiles', + fields: [ + { type: 'string', name: 'name' }, + { type: 'bigInt', name: 'userId' }, + { type: 'belongsTo', name: 'user', foreignKey: 'userId' }, + ], + }); + + await db.sync(); + + // create user + const user = await User.repository.create({ values: { name: 'user1' } }); + const profile = await Profile.repository.create({ values: { name: 'profile1' } }); + + const profileData = profile.toJSON(); + await User.repository.update({ + filterByTk: user.id, + values: { + profiles: [ + { + ...profileData, + userId: null, + }, + ], + }, + updateAssociationValues: ['profiles'], + }); + + const profile1 = await Profile.repository.findOne({ filterByTk: profile.id }); + expect(profile1['userId']).toBe(user.id); + }); + test('update belongs to with foreign key and object', async () => { const throughAB = db.collection({ name: 'throughAB', diff --git a/packages/core/database/src/update-associations.ts b/packages/core/database/src/update-associations.ts index ce973e5328..8259a1a7e4 100644 --- a/packages/core/database/src/update-associations.ts +++ b/packages/core/database/src/update-associations.ts @@ -351,7 +351,11 @@ export async function updateSingleAssociation( if (updateAssociationValues.includes(key)) { const updateValues = { ...value }; - delete updateValues[association.foreignKey]; + + if (association.associationType === 'HasOne') { + delete updateValues[association.foreignKey]; + } + await instance.update(updateValues, { ...options, transaction }); } @@ -536,6 +540,10 @@ export async function updateMultipleAssociation( continue; } if (updateAssociationValues.includes(key)) { + if (association.associationType === 'HasMany') { + delete item[association.foreignKey]; + } + await instance.update(item, { ...options, transaction }); } await updateAssociations(instance, item, {