Browse Source

fix: Extract primary key value properly when table missing auto-incremented/auto-generated primary key (#8480)

* fix: extract from insertobject if pk is not ai/ag

* fix: pass auto increment column

* refactor: remove unnecessary if case
pull/8484/head
Pranav C 2 months ago committed by GitHub
parent
commit
844507e01f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 21
      packages/nocodb/src/db/BaseModelSqlv2.ts

21
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -2760,6 +2760,7 @@ class BaseModelSqlv2 {
rowId: insertObj[ag.column_name], rowId: insertObj[ag.column_name],
insertObj, insertObj,
ag, ag,
ai,
}), }),
false, false,
{}, {},
@ -2803,7 +2804,7 @@ class BaseModelSqlv2 {
).__nc_ai_id; ).__nc_ai_id;
} }
response = await this.readByPk( response = await this.readByPk(
this.extractCompositePK({ rowId: id, insertObj, ag }), this.extractCompositePK({ rowId: id, insertObj, ag, ai }),
false, false,
{}, {},
{ ignoreView: true, getHiddenColumn: true }, { ignoreView: true, getHiddenColumn: true },
@ -3270,18 +3271,16 @@ class BaseModelSqlv2 {
} }
} }
rowId = pkObj; rowId = pkObj;
} else if ( } else if (!ai && !ag && insertObj) {
!ai &&
!ag &&
(force || this.model.primaryKeys?.length > 1 || this.isSnowflake)
) {
// handle if primary key is not ai or ag // handle if primary key is not ai or ag
const pkObj = {}; if (this.model.primaryKeys.length === 1) {
for (const pk of this.model.primaryKeys) { return insertObj[this.model.primaryKey.column_name] ?? null;
const key = pk.title; } else {
pkObj[key] = insertObj[pk.column_name] ?? null; return this.model.primaryKeys.reduce((acc, pk) => {
acc[pk.title] = insertObj[pk.column_name] ?? null;
return acc;
}, {});
} }
rowId = pkObj;
} }
return rowId; return rowId;

Loading…
Cancel
Save