|
|
|
@ -1423,7 +1423,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
// const driver = trx ? trx : this.dbDriver;
|
|
|
|
|
|
|
|
|
|
const query = this.dbDriver(this.tnPath).insert(insertObj); |
|
|
|
|
if (this.isPg || this.isMssql) { |
|
|
|
|
if ((this.isPg || this.isMssql) && this.model.primaryKey) { |
|
|
|
|
query.returning( |
|
|
|
|
`${this.model.primaryKey.column_name} as ${this.model.primaryKey.title}` |
|
|
|
|
); |
|
|
|
@ -1431,7 +1431,15 @@ class BaseModelSqlv2 {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const ai = this.model.columns.find((c) => c.ai); |
|
|
|
|
if ( |
|
|
|
|
|
|
|
|
|
let ag: Column; |
|
|
|
|
if (!ai) ag = this.model.columns.find((c) => c.meta?.ag); |
|
|
|
|
|
|
|
|
|
// handle if autogenerated primary key is used
|
|
|
|
|
if (ag) { |
|
|
|
|
if (!response) await this.extractRawQueryAndExec(query); |
|
|
|
|
response = await this.readByPk(data[ag.title]); |
|
|
|
|
} else if ( |
|
|
|
|
!response || |
|
|
|
|
(typeof response?.[0] !== 'object' && response?.[0] !== null) |
|
|
|
|
) { |
|
|
|
|