Browse Source

deleted columns with ai = true

pull/6878/head
Aashish Agrawal 1 year ago
parent
commit
915ccbd99a
  1. 18
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 6
      packages/nocodb/src/services/datas.service.ts

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

@ -2193,7 +2193,21 @@ class BaseModelSqlv2 {
await this.beforeInsert(insertObj, trx, cookie); await this.beforeInsert(insertObj, trx, cookie);
} }
await this.model.getColumns(); const columns = await this.model.getColumns();
//remove auto increment columns if present in body
for (const col of columns) {
if (col.ai == true) {
const keyName = data?.[col.column_name] !== undefined
? col.column_name
: col.title
if (data[keyName]) {
delete data[keyName]
}
}
}
await this.prepareAttachmentData(insertObj); await this.prepareAttachmentData(insertObj);
@ -2211,7 +2225,7 @@ class BaseModelSqlv2 {
const ai = this.model.columns.find((c) => c.ai); const ai = this.model.columns.find((c) => c.ai);
let ag: Column; let ag: Column;
if (!ai) ag = this.model.columns.find((c) => c.meta?.ag); if (!ai) ag = this.model.columns.find((c) => c.meta?.ag);
// handle if autogenerated primary key is used // handle if autogenerated primary key is used
if (ag) { if (ag) {

6
packages/nocodb/src/services/datas.service.ts

@ -63,7 +63,7 @@ export class DatasService {
async dataInsert( async dataInsert(
param: PathParams & { param: PathParams & {
body: any; body: unknown;
cookie: any; cookie: any;
disableOptimization?: boolean; disableOptimization?: boolean;
}, },
@ -78,10 +78,6 @@ export class DatasService {
dbDriver: await NcConnectionMgrv2.get(source), dbDriver: await NcConnectionMgrv2.get(source),
}); });
if (param?.body?.Id) {
delete param?.body?.Id
}
return await baseModel.insert(param.body, null, param.cookie); return await baseModel.insert(param.body, null, param.cookie);
} }

Loading…
Cancel
Save