From 2a12fea9e4863a6d6d800c7d35fc31f4bbc87e4f Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Sat, 3 Feb 2018 01:11:24 +0100
Subject: [PATCH] Do not add extra 'NOT NULL' when irrelevant

---
 parser.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

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,
 						});
 					});
-- 
2.44.0