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 model: childTable
}); });
const rtn = childTable.table_name; const rtn = childTable.table_name;
const rtnId = childTable.id;
const qb = this.dbDriver(rtn).join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`); const qb = this.dbDriver(rtn).join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`);
@ -551,7 +552,10 @@ class BaseModelSqlv2 {
const children = await finalQb; const children = await finalQb;
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ table_name: rtn, dbDriver: this.dbDriver }) await Model.getBaseModelSQL({
id: rtnId,
dbDriver: this.dbDriver
})
).getProto(); ).getProto();
const gs = _.groupBy( const gs = _.groupBy(
children.map(c => { children.map(c => {
@ -582,6 +586,7 @@ class BaseModelSqlv2 {
model: childTable model: childTable
}); });
const rtn = childTable.table_name; const rtn = childTable.table_name;
const rtnId = childTable.id;
const qb = this.dbDriver(rtn) const qb = this.dbDriver(rtn)
.join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`) .join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`)
@ -600,7 +605,7 @@ class BaseModelSqlv2 {
const children = await qb; const children = await qb;
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ table_name: rtn, dbDriver: this.dbDriver }) await Model.getBaseModelSQL({ id: rtnId, dbDriver: this.dbDriver })
).getProto(); ).getProto();
return children.map(c => { 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( public static async getBaseModelSQL(
args: { args: {
id?: string; id?: string;
table_name?: string;
viewId?: string; viewId?: string;
dbDriver: XKnex; dbDriver: XKnex;
model?: Model; model?: Model;
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<BaseModelSqlv2> { ): Promise<BaseModelSqlv2> {
const model = const model = args?.model || (await this.get(args.id, ncMeta));
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
// }));
return new BaseModelSqlv2({ return new BaseModelSqlv2({
dbDriver: args.dbDriver, dbDriver: args.dbDriver,

Loading…
Cancel
Save