new(basic.gblib): Allow relationships in TABLE keywod #381.

This commit is contained in:
Rodrigo Rodriguez 2023-10-08 16:03:33 -03:00
parent 0212ed6e21
commit 41f7eea81a

View file

@ -198,13 +198,18 @@ export class GBVMService extends GBService {
case 'boolean':
return { key: 'BOOLEAN' };
default:
return { key: 'STRING' }; // Default to string if the type is unknown
return { key: 'TABLE' , name: t};
}
};
const associations = [];
Object.keys(t.fields).forEach(key => {
let obj = t.fields[key];
obj.type = getTypeBasedOnCondition(obj.type);
if (obj.type.key === "TABLE"){
associations.push({from: t.name,to: obj.type.name});
}
if (obj.name.toLowerCase() === 'id')
{
obj['primaryKey'] = true;
@ -212,6 +217,15 @@ export class GBVMService extends GBService {
});
associations.forEach(e=>{
const from = minBoot.core.sequelize.models[e.from];
const to = minBoot.core.sequelize.models[e.to];
from.hasMany(to);
to.belongsTo(from);
});
minBoot.core.sequelize.define(t.name, t.fields);
await minBoot.core.sequelize.sync({