diff --git a/src/i18n/locales/en.js b/src/i18n/locales/en.js index a961c056e..0598c7f27 100644 --- a/src/i18n/locales/en.js +++ b/src/i18n/locales/en.js @@ -200,6 +200,7 @@ const en = { "Duplicate type fields by name '{{fieldName}}' in type '{{typeName}}'", duplicate_reference: "Duplicate reference by the name '{{refName}}'", circular_dependency: "Circular dependency involving table '{{refName}}'", + circular_type_dependency: "Circular type dependency involving type '{{typeName}}'", timeline: "Timeline", priority: "Priority", none: "None", diff --git a/src/i18n/locales/es.js b/src/i18n/locales/es.js index 5f8373134..814f6fd4c 100644 --- a/src/i18n/locales/es.js +++ b/src/i18n/locales/es.js @@ -195,6 +195,7 @@ const es = { "Campos de tipo duplicados por nombre '{{fieldName}}' en el tipo '{{typeName}}'", duplicate_reference: "Referencia duplicada con el nombre '{{refName}}'", circular_dependency: "Dependencia circular involucrando la tabla '{{refName}}'", + circular_type_dependency: "Dependencia circular de tipos involucrando el tipo '{{typeName}}'", timeline: "Linea del tiempo", priority: "Prioridad", none: "Ninguno", diff --git a/src/utils/issues.js b/src/utils/issues.js index 0553bb495..f4fd52d24 100644 --- a/src/utils/issues.js +++ b/src/utils/issues.js @@ -202,6 +202,7 @@ export function getIssues(diagram) { } }); + // Check for circular table relationships const visitedTables = new Set(); function checkCircularRelationships(tableId, visited = []) { @@ -230,5 +231,38 @@ export function getIssues(diagram) { } }); + // Check for circular type dependencies + function checkCircularTypes(typeName, visited = []) { + if (visited.includes(typeName)) { + issues.push( + i18n.t("circular_type_dependency", { + typeName: typeName, + }), + ); + return; + } + + const currentType = diagram.types.find((t) => t.name === typeName); + if (!currentType) return; + + visited.push(typeName); + + currentType.fields.forEach((field) => { + // Check if this field references another custom type + const referencedType = diagram.types.find((t) => t.name === field.type); + if (referencedType && field.type !== typeName) { + checkCircularTypes(field.type, [...visited]); + } + }); + } + + const visitedTypes = new Set(); + diagram.types.forEach((type) => { + if (!visitedTypes.has(type.name)) { + visitedTypes.add(type.name); + checkCircularTypes(type.name); + } + }); + return issues; }