mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Properly handle M2A fields in fieldStore and useFieldTree (#9432)
* Properly handle M2A fields in fieldStore and useFieldTree * Fix addNode * Rewrote use-field-tree * Remember visited paths * Fix error whith undefined relation.meta
This commit is contained in:
@@ -268,19 +268,21 @@ export const useFieldsStore = defineStore({
|
||||
*/
|
||||
getRelationalField(collection: string, fields: string) {
|
||||
const relationsStore = useRelationsStore();
|
||||
const parts = fields.split('.');
|
||||
const [field, ...path] = fields.split('.');
|
||||
if (field.includes(':')) {
|
||||
const [_, collection] = field.split(':');
|
||||
return this.getField(collection, path.join('.'));
|
||||
}
|
||||
|
||||
const relation = relationsStore
|
||||
.getRelationsForField(collection, parts[0])
|
||||
?.find(
|
||||
(relation: Relation) => relation.field === parts[0] || relation.meta?.one_field === parts[0]
|
||||
) as Relation;
|
||||
const relations = relationsStore.getRelationsForField(collection, field);
|
||||
const relation = relations?.find((relation: Relation) => {
|
||||
return relation.field === field || relation.meta?.one_field === field;
|
||||
});
|
||||
|
||||
if (relation === undefined) return false;
|
||||
|
||||
const relatedCollection = relation.field === parts[0] ? relation.related_collection : relation.collection;
|
||||
parts.shift();
|
||||
const relatedField = parts.join('.');
|
||||
const relatedCollection = relation.field === field ? relation.related_collection : relation.collection;
|
||||
const relatedField = path.join('.');
|
||||
return this.getField(relatedCollection, relatedField);
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user