fix: useSyncFromForm support multi-level relationships (#2413)

This commit is contained in:
katherinehhh 2023-08-08 15:37:10 +08:00 committed by GitHub
parent 3c161eab86
commit 823d4bd94d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -260,13 +260,13 @@ function loadChildren({ node, traverseAssociations, traverseFields, systemKeys,
const activeNode = findNode(fields.dataSource || fields.componentProps.treeData, node); const activeNode = findNode(fields.dataSource || fields.componentProps.treeData, node);
let children = []; let children = [];
// 多对多和多对一只展示关系字段 // 多对多和多对一只展示关系字段
if (['belongsTo', 'belongsToMany'].includes(node.field.type)) { if (['belongsTo', 'belongsToMany'].includes(node.field.type) && node?.type === 'reference') {
children = traverseAssociations(node.field.target, { children = traverseAssociations(node.field.target, {
exclude: systemKeys, exclude: systemKeys,
prefix: node.key, prefix: node.key,
maxDepth: 1, 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, { children = traverseFields(node.field.target, {
exclude: ['id', ...systemKeys], exclude: ['id', ...systemKeys],
prefix: node.key, prefix: node.key,

View File

@ -53,7 +53,7 @@ export const useSyncFromForm = (fieldSchema, collection?, callBack?) => {
field, field,
disabled, disabled,
}; };
const tatgetFormField = formData.find((v) => v.name === field.name); const tatgetFormField = formData.find((v) => v.name === option.key);
if ( if (
['belongsTo', 'belongsToMany'].includes(field.type) && ['belongsTo', 'belongsToMany'].includes(field.type) &&
(!tatgetFormField || ['Select', 'Picker'].includes(tatgetFormField?.fieldMode)) (!tatgetFormField || ['Select', 'Picker'].includes(tatgetFormField?.fieldMode))