From 862fe8815f9b5f20ecf357e526b799f505eff4f5 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 14 Nov 2022 12:33:57 +0800 Subject: [PATCH] fix(nocodb): fail to update records with multiple primary keys --- .../sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index f2c7ba99c2..5c07bb1e2e 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -97,7 +97,7 @@ class BaseModelSqlv2 { await this.selectObject({ qb }); - qb.where(this.model.primaryKey.column_name, id); + qb.where(_wherePk(this.model.primaryKeys, id)); const data = (await this.extractRawQueryAndExec(qb))?.[0]; @@ -390,7 +390,7 @@ class BaseModelSqlv2 { dbDriver: this.dbDriver, }); await parentTable.getColumns(); - + const childTn = this.getTnPath(childTable); const parentTn = this.getTnPath(parentTable); @@ -1628,9 +1628,9 @@ class BaseModelSqlv2 { private getTnPath(tb: Model) { const schema = (this.dbDriver as any).searchPath?.(); const table = - this.isMssql && schema - ? this.dbDriver.raw('??.??', [schema, tb.table_name]) - : tb.table_name; + this.isMssql && schema + ? this.dbDriver.raw('??.??', [schema, tb.table_name]) + : tb.table_name; return table; } @@ -1826,12 +1826,16 @@ class BaseModelSqlv2 { // refer : https://www.sqlite.org/limits.html const chunkSize = this.isSqlite ? 10 : _chunkSize; - const response = (this.isPg || this.isMssql) ? - await this.dbDriver - .batchInsert(this.model.table_name, insertDatas, chunkSize) - .returning(this.model.primaryKey?.column_name) : - await this.dbDriver - .batchInsert(this.model.table_name, insertDatas, chunkSize); + const response = + this.isPg || this.isMssql + ? await this.dbDriver + .batchInsert(this.model.table_name, insertDatas, chunkSize) + .returning(this.model.primaryKey?.column_name) + : await this.dbDriver.batchInsert( + this.model.table_name, + insertDatas, + chunkSize + ); await this.afterBulkInsert(insertDatas, this.dbDriver, cookie);