|
|
@ -1877,16 +1877,13 @@ class BaseModelSqlv2 { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async delByPk(id, _trx?, cookie?) { |
|
|
|
async delByPk(id, _trx?, cookie?) { |
|
|
|
const trx: Transaction = _trx; |
|
|
|
let trx: Transaction = _trx; |
|
|
|
try { |
|
|
|
try { |
|
|
|
// retrieve data for handling params in hook
|
|
|
|
// retrieve data for handling params in hook
|
|
|
|
const data = await this.readByPk(id); |
|
|
|
const data = await this.readByPk(id); |
|
|
|
await this.beforeDelete(id, trx, cookie); |
|
|
|
await this.beforeDelete(id, trx, cookie); |
|
|
|
|
|
|
|
|
|
|
|
// todo: use transaction
|
|
|
|
const execQueries: ((trx: Transaction) => Promise<any>)[] = []; |
|
|
|
// if (!trx) {
|
|
|
|
|
|
|
|
// trx = await this.dbDriver.transaction();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// start a transaction if not already in one
|
|
|
|
// start a transaction if not already in one
|
|
|
|
for (const column of this.model.columns) { |
|
|
|
for (const column of this.model.columns) { |
|
|
@ -1903,9 +1900,11 @@ class BaseModelSqlv2 { |
|
|
|
colId: colOptions.fk_mm_child_column_id, |
|
|
|
colId: colOptions.fk_mm_child_column_id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
await this.dbDriver(mmTable.table_name) |
|
|
|
execQueries.push((trx) => |
|
|
|
|
|
|
|
trx(mmTable.table_name) |
|
|
|
.del() |
|
|
|
.del() |
|
|
|
.where(mmParentColumn.column_name, id); |
|
|
|
.where(mmParentColumn.column_name, id), |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'hm': |
|
|
|
case 'hm': |
|
|
@ -1917,11 +1916,13 @@ class BaseModelSqlv2 { |
|
|
|
colId: colOptions.fk_child_column_id, |
|
|
|
colId: colOptions.fk_child_column_id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
await this.dbDriver(relatedTable.table_name) |
|
|
|
execQueries.push((trx) => |
|
|
|
|
|
|
|
trx(relatedTable.table_name) |
|
|
|
.update({ |
|
|
|
.update({ |
|
|
|
[childColumn.column_name]: null, |
|
|
|
[childColumn.column_name]: null, |
|
|
|
}) |
|
|
|
}) |
|
|
|
.where(childColumn.column_name, id); |
|
|
|
.where(childColumn.column_name, id), |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'bt': |
|
|
|
case 'bt': |
|
|
@ -1931,14 +1932,19 @@ class BaseModelSqlv2 { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await trx(this.model.table_name).where(column.column_name, id).del(); |
|
|
|
// await trx(this.model.table_name).where(column.column_name, id).del();
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!trx) { |
|
|
|
|
|
|
|
trx = await this.dbDriver.transaction(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// iterate over all columns and unlink all LTAR data
|
|
|
|
await Promise.all(execQueries.map((q) => q(trx))); |
|
|
|
|
|
|
|
|
|
|
|
const response = await this.dbDriver(this.tnPath) |
|
|
|
const response = await trx(this.tnPath) |
|
|
|
.del() |
|
|
|
.del() |
|
|
|
.where(await this._wherePk(id)); |
|
|
|
.where(await this._wherePk(id)); |
|
|
|
|
|
|
|
|
|
|
|
await this.afterDelete(data, trx, cookie); |
|
|
|
await this.afterDelete(data, trx, cookie); |
|
|
|
return response; |
|
|
|
return response; |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|