From d1dd7b08eb232459d0d301c67272dcacbab1f3cc Mon Sep 17 00:00:00 2001 From: Pranav C Date: Fri, 12 Jul 2024 18:22:06 +0000 Subject: [PATCH] refactor: coderabbit suggestions --- packages/nocodb/src/db/BaseModelSqlv2.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 37ac850cdf..1e20c527d2 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -6080,15 +6080,20 @@ class BaseModelSqlv2 { // 2. check current child is linked with another row cell linkedOoRowObj = await this.execAndParse( this.dbDriver(childTn) - .select(childColumn.column_name) - .select(childColumn.column_name) + .select( + ...new Set( + [childColumn, ...childTable.primaryKeys].map( + (col) => `${childTable.table_name}.${col.column_name}`, + ), + ), + ) .where(_wherePk(childTable.primaryKeys, childId)), null, { raw: true, first: true }, ); const oldRowId = linkedOoRowObj - ? Object.values(linkedOoRowObj)?.[0] + ? linkedOoRowObj[childTable.primaryKeys[0]?.column_name] : null; if (oldRowId) { const [parentRelatedPkValue, childRelatedPkValue] = @@ -7392,7 +7397,7 @@ class BaseModelSqlv2 { }); const parentBaseModel = await Model.getBaseModelSQL(this.context, { - model: childTable, + model: parentTable, dbDriver: this.dbDriver, }); @@ -7782,7 +7787,7 @@ class BaseModelSqlv2 { }); const parentBaseModel = await Model.getBaseModelSQL(this.context, { - model: childTable, + model: parentTable, dbDriver: this.dbDriver, });