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, });