|
|
@ -2813,13 +2813,15 @@ class BaseModelSqlv2 { |
|
|
|
async delByPk(id, _trx?, cookie?) { |
|
|
|
async delByPk(id, _trx?, cookie?) { |
|
|
|
let trx: Knex.Transaction = _trx; |
|
|
|
let trx: Knex.Transaction = _trx; |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
const source = await Source.get(this.model.source_id); |
|
|
|
// retrieve data for handling params in hook
|
|
|
|
// retrieve data for handling params in hook
|
|
|
|
const data = await this.readByPk( |
|
|
|
const data = await this.readRecord({ |
|
|
|
id, |
|
|
|
idOrRecord: id, |
|
|
|
false, |
|
|
|
validateFormula: false, |
|
|
|
{}, |
|
|
|
ignoreView: true, |
|
|
|
{ ignoreView: true, getHiddenColumn: true }, |
|
|
|
getHiddenColumn: true, |
|
|
|
); |
|
|
|
source, |
|
|
|
|
|
|
|
}); |
|
|
|
await this.beforeDelete(id, trx, cookie); |
|
|
|
await this.beforeDelete(id, trx, cookie); |
|
|
|
|
|
|
|
|
|
|
|
const execQueries: ((trx: Knex.Transaction) => Promise<any>)[] = []; |
|
|
|
const execQueries: ((trx: Knex.Transaction) => Promise<any>)[] = []; |
|
|
@ -3056,9 +3058,31 @@ class BaseModelSqlv2 { |
|
|
|
return this.dbDriver.clientType(); |
|
|
|
return this.dbDriver.clientType(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async readRecord(params: { |
|
|
|
|
|
|
|
idOrRecord: string | Record<string, any>; |
|
|
|
|
|
|
|
fieldsSet?: Set<string>; |
|
|
|
|
|
|
|
ignoreView?: boolean; |
|
|
|
|
|
|
|
getHiddenColumn?: boolean; |
|
|
|
|
|
|
|
validateFormula?: boolean; |
|
|
|
|
|
|
|
source: Source; |
|
|
|
|
|
|
|
disableOptimization?: boolean; |
|
|
|
|
|
|
|
view?: View; |
|
|
|
|
|
|
|
}): Promise<any> { |
|
|
|
|
|
|
|
return this.readByPk( |
|
|
|
|
|
|
|
params.idOrRecord, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
{}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ignoreView: params.ignoreView, |
|
|
|
|
|
|
|
getHiddenColumn: params.getHiddenColumn, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async nestedInsert(data, _trx = null, cookie?) { |
|
|
|
async nestedInsert(data, _trx = null, cookie?) { |
|
|
|
// const driver = trx ? trx : await this.dbDriver.transaction();
|
|
|
|
// const driver = trx ? trx : await this.dbDriver.transaction();
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
const source = await Source.get(this.model.source_id); |
|
|
|
await populatePk(this.model, data); |
|
|
|
await populatePk(this.model, data); |
|
|
|
const insertObj = await this.model.mapAliasToColumn( |
|
|
|
const insertObj = await this.model.mapAliasToColumn( |
|
|
|
data, |
|
|
|
data, |
|
|
@ -3102,12 +3126,13 @@ class BaseModelSqlv2 { |
|
|
|
// handle if autogenerated primary key is used
|
|
|
|
// handle if autogenerated primary key is used
|
|
|
|
if (ag) { |
|
|
|
if (ag) { |
|
|
|
if (!response) await this.execAndParse(query); |
|
|
|
if (!response) await this.execAndParse(query); |
|
|
|
response = await this.readByPk( |
|
|
|
response = await this.readRecord({ |
|
|
|
insertObj[ag.column_name], |
|
|
|
idOrRecord: insertObj[ag.column_name], |
|
|
|
false, |
|
|
|
ignoreView: true, |
|
|
|
{}, |
|
|
|
getHiddenColumn: true, |
|
|
|
{ ignoreView: true, getHiddenColumn: true }, |
|
|
|
validateFormula: false, |
|
|
|
); |
|
|
|
source, |
|
|
|
|
|
|
|
}); |
|
|
|
} else if ( |
|
|
|
} else if ( |
|
|
|
!response || |
|
|
|
!response || |
|
|
|
(typeof response?.[0] !== 'object' && response?.[0] !== null) |
|
|
|
(typeof response?.[0] !== 'object' && response?.[0] !== null) |
|
|
@ -3166,12 +3191,13 @@ class BaseModelSqlv2 { |
|
|
|
await Promise.all(postInsertOps.map((f) => f(rowId))); |
|
|
|
await Promise.all(postInsertOps.map((f) => f(rowId))); |
|
|
|
|
|
|
|
|
|
|
|
if (rowId !== null && rowId !== undefined) { |
|
|
|
if (rowId !== null && rowId !== undefined) { |
|
|
|
response = await this.readByPk( |
|
|
|
response = await this.readRecord({ |
|
|
|
rowId, |
|
|
|
idOrRecord: rowId, |
|
|
|
false, |
|
|
|
validateFormula: false, |
|
|
|
{}, |
|
|
|
ignoreView: true, |
|
|
|
{ ignoreView: true, getHiddenColumn: true }, |
|
|
|
getHiddenColumn: true, |
|
|
|
); |
|
|
|
source, |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await this.afterInsert(response, this.dbDriver, cookie); |
|
|
|
await this.afterInsert(response, this.dbDriver, cookie); |
|
|
|