|
|
|
@ -737,8 +737,6 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
|
|
|
|
|
protected initDbDriver(): void { |
|
|
|
|
if (!this.dbDriver) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.connectionConfig?.connection?.ssl && typeof this.connectionConfig?.connection?.ssl === 'object') { |
|
|
|
|
if (this.connectionConfig.connection.ssl.caFilePath) { |
|
|
|
|
this.connectionConfig.connection.ssl.ca = fs |
|
|
|
@ -1497,6 +1495,64 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
|
|
|
|
|
public getProjectId() { |
|
|
|
|
return this.projectId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected async getManyToManyRelations() { |
|
|
|
|
const metas = new Set<any>(); |
|
|
|
|
|
|
|
|
|
for (const meta of Object.values(this.metas)) { |
|
|
|
|
|
|
|
|
|
// check if table is a Bridge table(or Associative Table) by checking
|
|
|
|
|
// number of foreign keys and columns
|
|
|
|
|
if (meta.belongsTo?.length === 2 && meta.columns.length < 4) { |
|
|
|
|
const tableMetaA = this.metas[meta.belongsTo[0].rtn]; |
|
|
|
|
const tableMetaB = this.metas[meta.belongsTo[1].rtn]; |
|
|
|
|
|
|
|
|
|
// add manytomany data under metadata of both related columns
|
|
|
|
|
tableMetaA.manyToMany = tableMetaA.manyToMany || []; |
|
|
|
|
tableMetaA.manyToMany.push({ |
|
|
|
|
"tn": tableMetaA.tn, |
|
|
|
|
"cn": meta.belongsTo[0].rcn, |
|
|
|
|
"vtn": meta.tn, |
|
|
|
|
"vcn": meta.belongsTo[0].cn, |
|
|
|
|
"vrcn": meta.belongsTo[1].cn, |
|
|
|
|
"rtn": meta.belongsTo[1].rtn, |
|
|
|
|
"rcn": meta.belongsTo[1].rcn, |
|
|
|
|
"_tn": tableMetaA._tn, |
|
|
|
|
"_cn": meta.belongsTo[0]._rcn, |
|
|
|
|
"_rtn": meta.belongsTo[1]._rtn, |
|
|
|
|
"_rcn": meta.belongsTo[1]._rcn |
|
|
|
|
}) |
|
|
|
|
tableMetaB.manyToMany = tableMetaB.manyToMany || []; |
|
|
|
|
tableMetaB.manyToMany.push({ |
|
|
|
|
"tn": tableMetaB.tn, |
|
|
|
|
"cn": meta.belongsTo[1].rcn, |
|
|
|
|
"vtn": meta.tn, |
|
|
|
|
"vcn": meta.belongsTo[1].cn, |
|
|
|
|
"vrcn": meta.belongsTo[0].cn, |
|
|
|
|
"rtn": meta.belongsTo[0].rtn, |
|
|
|
|
"rcn": meta.belongsTo[0].rcn, |
|
|
|
|
"_tn": tableMetaB._tn, |
|
|
|
|
"_cn": meta.belongsTo[1]._rcn, |
|
|
|
|
"_rtn": meta.belongsTo[0]._rtn, |
|
|
|
|
"_rcn": meta.belongsTo[0]._rcn |
|
|
|
|
}) |
|
|
|
|
metas.add(tableMetaA) |
|
|
|
|
metas.add(tableMetaB) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Update metadata of tables which have manytomany relation
|
|
|
|
|
// and recreate basemodel with new meta information
|
|
|
|
|
for (const meta of metas) { |
|
|
|
|
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { |
|
|
|
|
meta: JSON.stringify(meta) |
|
|
|
|
}, {title: meta.tn}) |
|
|
|
|
XcCache.del([this.projectId, this.dbAlias, 'table', meta.tn].join('::')); |
|
|
|
|
this.models[meta.tn] = this.getBaseModel(meta) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export {IGNORE_TABLES}; |
|
|
|
|