new(basic.gblib): Allow relationships in TABLE keywod #381.
This commit is contained in:
parent
0212ed6e21
commit
41f7eea81a
1 changed files with 15 additions and 1 deletions
|
@ -198,13 +198,18 @@ export class GBVMService extends GBService {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return { key: 'BOOLEAN' };
|
return { key: 'BOOLEAN' };
|
||||||
default:
|
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 => {
|
Object.keys(t.fields).forEach(key => {
|
||||||
let obj = t.fields[key];
|
let obj = t.fields[key];
|
||||||
obj.type = getTypeBasedOnCondition(obj.type);
|
obj.type = getTypeBasedOnCondition(obj.type);
|
||||||
|
if (obj.type.key === "TABLE"){
|
||||||
|
associations.push({from: t.name,to: obj.type.name});
|
||||||
|
}
|
||||||
if (obj.name.toLowerCase() === 'id')
|
if (obj.name.toLowerCase() === 'id')
|
||||||
{
|
{
|
||||||
obj['primaryKey'] = true;
|
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);
|
minBoot.core.sequelize.define(t.name, t.fields);
|
||||||
|
|
||||||
await minBoot.core.sequelize.sync({
|
await minBoot.core.sequelize.sync({
|
||||||
|
|
Loading…
Add table
Reference in a new issue