X-Git-Url: https://git.auder.net/doc/vendor/underscore-min.js?a=blobdiff_plain;f=parser.js;h=5ef2b3f25ba7ebb72fe58a6e0c93e3b30fdcc8e9;hb=2906c5327f141d94aacc7ee65c3595a4f940cf37;hp=2b75709dddeae00dddf82d8787b9d686a7d70033;hpb=8edb29ffa12fda61a939295ce00a6d22133131d1;p=erdiag.git diff --git a/parser.js b/parser.js index 2b75709..5ef2b3f 100644 --- a/parser.js +++ b/parser.js @@ -172,8 +172,11 @@ class ErDiags isKey: attr.isKey, qualifiers: attr.qualifiers, }; - if (!!attr.qualifiers && !!attr.qualifiers.match(/foreign/i)) + if (!!attr.qualifiers && !!attr.qualifiers.match(/references/i)) + { Object.assign(newField, {ref: attr.qualifiers.match(/references ([^\s]+)/i)[1]}); + attr.qualifiers = attr.qualifiers.replace(/references [^\s]+/, ""); + } newTable.push(newField); }); this.tables[name] = newTable; @@ -187,8 +190,8 @@ class ErDiags name: inh.parent + "_id", type: this.tables[inh.parent][idx].type, isKey: true, - qualifiers: (this.tables[inh.parent][idx].qualifiers || "") + " foreign key references " + inh.parent, - ref: inh.parent, + qualifiers: this.tables[inh.parent][idx].qualifiers || "", + ref: inh.parent + "(" + this.tables[inh.parent][idx].name + ")", }); }); }); @@ -207,12 +210,14 @@ 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" : ""), - ref: e2.name, //easier drawMld function (fewer regexps) + qualifiers: !isKey && e.card[0]=='1' ? "not null" : "", + ref: e2.name + "(" + attr.name + ")", }); } }); @@ -241,8 +246,8 @@ class ErDiags name: item.entity + "_" + f.name, isKey: true, type: f.type, - qualifiers: (f.qualifiers || "") + " foreign key references " + item.entity + " not null", - ref: item.entity, + qualifiers: f.qualifiers || "", + ref: item.entity + "(" + f.name + ")", }); }); }); @@ -445,20 +450,11 @@ class ErDiags mldDot += '