// attributes: ArrayOf {name, [isKey], [type], [qualifiers]}
parseAttributes(lines, start, end)
{
- let attributes = [];
+ let attributes = [ ];
for (let i=start; i<end; i++)
{
let field = { };
let line = lines[i];
- if (line.charAt(0) == '#')
+ if (line.charAt(0) == '+')
{
field.isKey = true;
line = line.slice(1);
// Pass 2: parse associations, add foreign keys when cardinality is 0,1 or 1,1
this.associations.forEach( a => {
let newTableAttrs = [ ];
+ let hasZeroOne = false;
a.entities.forEach( e => {
if (['?','1'].includes(e.card[0]))
{
+ hasZeroOne = true;
// Foreign key apparition (for each entity in association minus current one, for each identifying attribute)
a.entities.forEach( e2 => {
if (e2.name == e.name)
return;
- e2.attributes.forEach( attr => {
+ this.entities[e2.name].attributes.forEach( attr => {
if (attr.isKey)
{
this.tables[e.name].push({
});
}
});
- if (newTableAttrs.length > 1)
+ if (!hasZeroOne && newTableAttrs.length > 1)
{
// Ok, really create a new table
let newTable = {
});
});
// Add relationship potential own attributes
- a.attributes.forEach( attr => {
+ (a.attributes || [ ]).forEach( attr => {
newTable.fields.push({
name: attr.name,
isKey: false,