From: Benjamin Auder Date: Sat, 3 Feb 2018 00:11:24 +0000 (+0100) Subject: Do not add extra 'NOT NULL' when irrelevant X-Git-Url: https://git.auder.net/js/current/pieces/doc/index.css?a=commitdiff_plain;h=2a12fea9e4863a6d6d800c7d35fc31f4bbc87e4f;p=erdiag.git Do not add extra 'NOT NULL' when irrelevant --- diff --git a/parser.js b/parser.js index 2b75709..65ac9ec 100644 --- a/parser.js +++ b/parser.js @@ -207,11 +207,13 @@ class ErDiags this.entities[e2.name].attributes.forEach( attr => { if (attr.isKey) { + // For "weak tables", foreign keys become part of the key + const isKey = e.card.length >= 2 && e.card[1] == 'R'; this.tables[e.name].push({ - isKey: e.card.length >= 2 && e.card[1] == 'R', //"weak tables" foreign keys become part of the key + isKey: isKey, name: e2.name + "_" + attr.name, type: attr.type, - qualifiers: "foreign key references " + e2.name + " " + (e.card[0]=='1' ? "not null" : ""), + qualifiers: "foreign key references " + e2.name + " " + (!isKey && e.card[0]=='1' ? "not null" : ""), ref: e2.name, //easier drawMld function (fewer regexps) }); } @@ -241,7 +243,7 @@ class ErDiags name: item.entity + "_" + f.name, isKey: true, type: f.type, - qualifiers: (f.qualifiers || "") + " foreign key references " + item.entity + " not null", + qualifiers: (f.qualifiers || "") + " foreign key references " + item.entity, ref: item.entity, }); });