|
|
@ -710,7 +710,6 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami |
|
|
|
this.baseLog(`onTableUpdate : Generating model instance for '%s' table`, tn) |
|
|
|
this.baseLog(`onTableUpdate : Generating model instance for '%s' table`, tn) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await NcHelp.executeOperations(aclOper, this.connectionConfig.client); |
|
|
|
await NcHelp.executeOperations(aclOper, this.connectionConfig.client); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -910,11 +909,17 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami |
|
|
|
childMeta.manyToMany = childMeta.manyToMany.filter(mm => !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent)) |
|
|
|
childMeta.manyToMany = childMeta.manyToMany.filter(mm => !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent)) |
|
|
|
|
|
|
|
|
|
|
|
// filter lookup and relation virtual columns
|
|
|
|
// filter lookup and relation virtual columns
|
|
|
|
parentMeta.v = parentMeta.v.filter(({mm, ...rest}) => (!mm || !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent)) |
|
|
|
parentMeta.v = parentMeta.v.filter(({ |
|
|
|
|
|
|
|
mm, |
|
|
|
|
|
|
|
...rest |
|
|
|
|
|
|
|
}) => (!mm || !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent)) |
|
|
|
// check for lookup
|
|
|
|
// check for lookup
|
|
|
|
&& !(rest.lk && rest.lk.type === 'mm' && (rest.lk.tn === parent && rest.lk.rtn === child || rest.lk.tn === child && rest.lk.rtn === parent)) |
|
|
|
&& !(rest.lk && rest.lk.type === 'mm' && (rest.lk.tn === parent && rest.lk.rtn === child || rest.lk.tn === child && rest.lk.rtn === parent)) |
|
|
|
) |
|
|
|
) |
|
|
|
childMeta.v = childMeta.v.filter(({mm, ...rest}) => (!mm || !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent)) |
|
|
|
childMeta.v = childMeta.v.filter(({ |
|
|
|
|
|
|
|
mm, |
|
|
|
|
|
|
|
...rest |
|
|
|
|
|
|
|
}) => (!mm || !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent)) |
|
|
|
// check for lookup
|
|
|
|
// check for lookup
|
|
|
|
&& !(rest.lk && rest.lk.type === 'mm' && (rest.lk.tn === parent && rest.lk.rtn === child || rest.lk.tn === child && rest.lk.rtn === parent)) |
|
|
|
&& !(rest.lk && rest.lk.type === 'mm' && (rest.lk.tn === parent && rest.lk.rtn === child || rest.lk.tn === child && rest.lk.rtn === parent)) |
|
|
|
) |
|
|
|
) |
|
|
@ -952,17 +957,17 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected initDbDriver(): void { |
|
|
|
protected initDbDriver(): void { |
|
|
|
this.dbDriver = NcConnectionMgr.get({ |
|
|
|
this.dbDriver = NcConnectionMgr.get({ |
|
|
|
dbAlias:this.dbAlias, |
|
|
|
dbAlias: this.dbAlias, |
|
|
|
env:this.config.env, |
|
|
|
env: this.config.env, |
|
|
|
config:this.config, |
|
|
|
config: this.config, |
|
|
|
projectId:this.projectId |
|
|
|
projectId: this.projectId |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.sqlClient = NcConnectionMgr.getSqlClient({ |
|
|
|
this.sqlClient = NcConnectionMgr.getSqlClient({ |
|
|
|
dbAlias:this.dbAlias, |
|
|
|
dbAlias: this.dbAlias, |
|
|
|
env:this.config.env, |
|
|
|
env: this.config.env, |
|
|
|
config:this.config, |
|
|
|
config: this.config, |
|
|
|
projectId:this.projectId |
|
|
|
projectId: this.projectId |
|
|
|
}) |
|
|
|
}) |
|
|
|
// if (!this.dbDriver) {
|
|
|
|
// if (!this.dbDriver) {
|
|
|
|
// if(this.projectBuilder?.prefix){
|
|
|
|
// if(this.projectBuilder?.prefix){
|
|
|
@ -1092,10 +1097,16 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami |
|
|
|
return ctx; |
|
|
|
return ctx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected getTableNameAlias(tn: string) { |
|
|
|
protected getTableNameAlias(tableName: string) { |
|
|
|
|
|
|
|
let tn = tableName; |
|
|
|
if (this.metas?.[tn]?._tn) { |
|
|
|
if (this.metas?.[tn]?._tn) { |
|
|
|
return this.metas?.[tn]?._tn; |
|
|
|
return this.metas?.[tn]?._tn; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.projectBuilder?.prefix) { |
|
|
|
|
|
|
|
tn = tn.replace(this.projectBuilder?.prefix, '') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const modifiedTableName = tn?.replace(/^(?=\d+)/, 'ISN___') |
|
|
|
const modifiedTableName = tn?.replace(/^(?=\d+)/, 'ISN___') |
|
|
|
return this.getInflectedName(modifiedTableName, this.connectionConfig?.meta?.inflection?.tn); |
|
|
|
return this.getInflectedName(modifiedTableName, this.connectionConfig?.meta?.inflection?.tn); |
|
|
|
} |
|
|
|
} |
|
|
@ -1104,8 +1115,8 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami |
|
|
|
this.baseLog(`generateContextForHasMany : '%s' => '%s'`, ctx.tn, tnc); |
|
|
|
this.baseLog(`generateContextForHasMany : '%s' => '%s'`, ctx.tn, tnc); |
|
|
|
return { |
|
|
|
return { |
|
|
|
...ctx, |
|
|
|
...ctx, |
|
|
|
_tn: this.metas[ctx.tn]._tn, |
|
|
|
_tn: this.metas[ctx.tn]?._tn, |
|
|
|
_ctn: this.metas[tnc]._tn, |
|
|
|
_ctn: this.metas[tnc]?._tn, |
|
|
|
ctn: tnc, |
|
|
|
ctn: tnc, |
|
|
|
project_id: this.projectId |
|
|
|
project_id: this.projectId |
|
|
|
}; |
|
|
|
}; |
|
|
@ -1426,10 +1437,10 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami |
|
|
|
// todo: ignore duplicate m2m relations
|
|
|
|
// todo: ignore duplicate m2m relations
|
|
|
|
// todo: optimize, just compare associative table(Vtn)
|
|
|
|
// todo: optimize, just compare associative table(Vtn)
|
|
|
|
...meta.manyToMany.filter((v, i) => !meta.v.some(v1 => v1.mm |
|
|
|
...meta.manyToMany.filter((v, i) => !meta.v.some(v1 => v1.mm |
|
|
|
&& ( |
|
|
|
&& ( |
|
|
|
v1.mm.tn === v.tn && v.rtn === v1.mm.rtn |
|
|
|
v1.mm.tn === v.tn && v.rtn === v1.mm.rtn |
|
|
|
|| v1.mm.rtn === v.tn && v.tn === v1.mm.rtn |
|
|
|
|| v1.mm.rtn === v.tn && v.tn === v1.mm.rtn |
|
|
|
) && v.vtn === v1.mm.vtn) |
|
|
|
) && v.vtn === v1.mm.vtn) |
|
|
|
// ignore duplicate
|
|
|
|
// ignore duplicate
|
|
|
|
&& !meta.manyToMany.some((v1, i1) => i1 !== i && v1.tn === v.tn && v.rtn === v1.rtn && v.vtn === v1.vtn) |
|
|
|
&& !meta.manyToMany.some((v1, i1) => i1 !== i && v1.tn === v.tn && v.rtn === v1.rtn && v.vtn === v1.vtn) |
|
|
|
).map(mm => { |
|
|
|
).map(mm => { |
|
|
|