From 823d4bd94d6efcf2bfcae82a0ddc1a25a3e743ca Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Tue, 8 Aug 2023 15:37:10 +0800 Subject: [PATCH] fix: useSyncFromForm support multi-level relationships (#2413) --- .../schema-settings/DataTemplates/hooks/useCollectionState.ts | 4 ++-- .../core/client/src/schema-settings/DataTemplates/utils.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/schema-settings/DataTemplates/hooks/useCollectionState.ts b/packages/core/client/src/schema-settings/DataTemplates/hooks/useCollectionState.ts index 630567cee..9bad5f096 100644 --- a/packages/core/client/src/schema-settings/DataTemplates/hooks/useCollectionState.ts +++ b/packages/core/client/src/schema-settings/DataTemplates/hooks/useCollectionState.ts @@ -260,13 +260,13 @@ function loadChildren({ node, traverseAssociations, traverseFields, systemKeys, const activeNode = findNode(fields.dataSource || fields.componentProps.treeData, node); let children = []; // 多对多和多对一只展示关系字段 - if (['belongsTo', 'belongsToMany'].includes(node.field.type)) { + if (['belongsTo', 'belongsToMany'].includes(node.field.type) && node?.type === 'reference') { children = traverseAssociations(node.field.target, { exclude: systemKeys, prefix: node.key, maxDepth: 1, }); - } else if (['hasOne', 'hasMany'].includes(node.field.type)) { + } else if (['hasOne', 'hasMany'].includes(node.field.type) || node?.type === 'duplicate') { children = traverseFields(node.field.target, { exclude: ['id', ...systemKeys], prefix: node.key, diff --git a/packages/core/client/src/schema-settings/DataTemplates/utils.tsx b/packages/core/client/src/schema-settings/DataTemplates/utils.tsx index 57cdedad9..fa4e63ceb 100644 --- a/packages/core/client/src/schema-settings/DataTemplates/utils.tsx +++ b/packages/core/client/src/schema-settings/DataTemplates/utils.tsx @@ -53,7 +53,7 @@ export const useSyncFromForm = (fieldSchema, collection?, callBack?) => { field, disabled, }; - const tatgetFormField = formData.find((v) => v.name === field.name); + const tatgetFormField = formData.find((v) => v.name === option.key); if ( ['belongsTo', 'belongsToMany'].includes(field.type) && (!tatgetFormField || ['Select', 'Picker'].includes(tatgetFormField?.fieldMode))