Do not add extra 'NOT NULL' when irrelevant
authorBenjamin Auder <benjamin.auder@somewhere>
Sat, 3 Feb 2018 00:11:24 +0000 (01:11 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sat, 3 Feb 2018 00:11:24 +0000 (01:11 +0100)
parser.js

index 2b75709..65ac9ec 100644 (file)
--- 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,
                                                });
                                        });