Browse Source

refactor: give auto generated key priority among primary keys

pull/7649/head
Pranav C 9 months ago
parent
commit
514ca8835f
  1. 7
      packages/nocodb/src/models/Model.ts

7
packages/nocodb/src/models/Model.ts

@ -80,7 +80,12 @@ export default class Model implements TableType {
public get primaryKey(): Column { public get primaryKey(): Column {
if (!this.columns) return null; if (!this.columns) return null;
return this.columns?.find((c) => c.pk); // return first auto increment or augto generated column
// if not found return first pk column
return (
this.columns.find((c) => c.pk && (c.ai || c.meta?.ag)) ||
this.columns?.find((c) => c.pk)
);
} }
public get primaryKeys(): Column[] { public get primaryKeys(): Column[] {

Loading…
Cancel
Save