Browse Source

fix: get table model by id instead of name

re #1946

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1951/head
Pranav C 3 years ago
parent
commit
1b9b964248
  1. 9
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts
  2. 26
      packages/nocodb/src/lib/noco-models/Model.ts

9
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts

@ -523,6 +523,7 @@ class BaseModelSqlv2 {
model: childTable
});
const rtn = childTable.table_name;
const rtnId = childTable.id;
const qb = this.dbDriver(rtn).join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`);
@ -551,7 +552,10 @@ class BaseModelSqlv2 {
const children = await finalQb;
const proto = await (
await Model.getBaseModelSQL({ table_name: rtn, dbDriver: this.dbDriver })
await Model.getBaseModelSQL({
id: rtnId,
dbDriver: this.dbDriver
})
).getProto();
const gs = _.groupBy(
children.map(c => {
@ -582,6 +586,7 @@ class BaseModelSqlv2 {
model: childTable
});
const rtn = childTable.table_name;
const rtnId = childTable.id;
const qb = this.dbDriver(rtn)
.join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`)
@ -600,7 +605,7 @@ class BaseModelSqlv2 {
const children = await qb;
const proto = await (
await Model.getBaseModelSQL({ table_name: rtn, dbDriver: this.dbDriver })
await Model.getBaseModelSQL({ id: rtnId, dbDriver: this.dbDriver })
).getProto();
return children.map(c => {

26
packages/nocodb/src/lib/noco-models/Model.ts

@ -317,37 +317,13 @@ export default class Model implements TableType {
public static async getBaseModelSQL(
args: {
id?: string;
table_name?: string;
viewId?: string;
dbDriver: XKnex;
model?: Model;
},
ncMeta = Noco.ncMeta
): Promise<BaseModelSqlv2> {
const model =
args?.model ||
(await this.getByIdOrName(
{
id: args.id,
table_name: args.table_name
},
ncMeta
));
// if (
// this.baseModels?.[model.base_id]?.[model.db_alias]?.[args.table_name || args.id]
// ) {
// return this.baseModels[model.base_id][model.db_alias][args.table_name || args.id];
// }
// this.baseModels[model.base_id] = this.baseModels[model.base_id] || {};
// this.baseModels[model.base_id][model.db_alias] =
// this.baseModels[model.base_id][model.db_alias] || {};
// return (this.baseModels[model.base_id][model.db_alias][
// args.table_name || args.id
// ] = new BaseModelSqlv2({
// dbDriver: args.dbDriver,
// model
// }));
const model = args?.model || (await this.get(args.id, ncMeta));
return new BaseModelSqlv2({
dbDriver: args.dbDriver,

Loading…
Cancel
Save