From 67366fb26630c4903fd3f252ffed7db5d2cbe76e Mon Sep 17 00:00:00 2001 From: Erik Ejlskov Jensen Date: Thu, 21 Dec 2023 13:43:49 +0100 Subject: [PATCH] add unique symbol --- .../Mermaid/DatabaseModelToMermaid.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/GUI/RevEng.Core.60/Mermaid/DatabaseModelToMermaid.cs b/src/GUI/RevEng.Core.60/Mermaid/DatabaseModelToMermaid.cs index 0959f7362..3571dbff5 100644 --- a/src/GUI/RevEng.Core.60/Mermaid/DatabaseModelToMermaid.cs +++ b/src/GUI/RevEng.Core.60/Mermaid/DatabaseModelToMermaid.cs @@ -55,14 +55,22 @@ public string CreateMermaid() foreach (var foreignKey in table.ForeignKeys) { - var relationship = "}o--||"; - //TODO: detect 1:1, 1:n, n:n - if (foreignKey.Columns.Any(c => c.IsNullable)) + var relationship = "}o--|"; + + var dependentIndexes = foreignKey.PrincipalTable.Indexes + .Where(i => i.Columns.SequenceEqual(foreignKey.PrincipalColumns)); + + if (dependentIndexes.Any(i => i.IsUnique)) + { + relationship = "|o--|"; + } + + if (foreignKey.PrincipalColumns.Any(c => c.IsNullable)) { - relationship = "}o--o|"; + relationship = "}o--o"; } - sb.AppendLine(CultureInfo.InvariantCulture, $" {formattedTableName} {relationship} {foreignKey.PrincipalTable.Name} : {foreignKey.Name}"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {formattedTableName} {relationship}| {foreignKey.PrincipalTable.Name} : {foreignKey.Name}"); } }