Browse Source

Merge pull request #1951 from nocodb/fix/1946-nested-lookup

fix: Nested lookup
pull/1954/head
navi 3 years ago committed by GitHub
parent
commit
79afaab3c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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