Browse Source

fix: nested link with ag pk (#8690)

* fix: extract ag pk

* fix: PR requested changes

* fix: condition for extract rowId

Signed-off-by: mertmit <mertmit99@gmail.com>

---------

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/8695/head
Mert E 7 months ago committed by GitHub
parent
commit
8a520daaaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      packages/nocodb/src/db/BaseModelSqlv2.ts

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

@ -3563,6 +3563,7 @@ class BaseModelSqlv2 {
// handle if autogenerated primary key is used
if (ag) {
rowId = insertObj[ag.column_name];
if (!response) await this.execAndParse(query);
response = await this.readRecord({
idOrRecord: insertObj[ag.column_name],
@ -3660,14 +3661,14 @@ class BaseModelSqlv2 {
force?: boolean;
}) {
// handle if composite primary key is used along with ai or ag
if ((ai || ag) && (force || this.model.primaryKeys?.length > 1)) {
if (ag) {
return insertObj[ag.column_name] ?? rowId;
} else if (ai && (force || this.model.primaryKeys?.length > 1)) {
// generate object with ai column and rest of the primary keys
const pkObj = {};
for (const pk of this.model.primaryKeys) {
const key = pk.title;
if (ai && pk.id === ai.id) {
pkObj[key] = rowId;
} else if (ag && pk.id === ag.id) {
if (ai && pk.id === ai.id && !(rowId === null || rowId === undefined)) {
pkObj[key] = rowId;
} else {
pkObj[key] = insertObj[pk.column_name] ?? null;

Loading…
Cancel
Save