|
|
|
@ -149,13 +149,18 @@ class BaseModelSqlv2 {
|
|
|
|
|
id?: any, |
|
|
|
|
validateFormula = false, |
|
|
|
|
query: any = {}, |
|
|
|
|
{ |
|
|
|
|
ignoreView = false, |
|
|
|
|
}: { |
|
|
|
|
ignoreView?: boolean; |
|
|
|
|
} = {}, |
|
|
|
|
): Promise<any> { |
|
|
|
|
const qb = this.dbDriver(this.tnPath); |
|
|
|
|
|
|
|
|
|
const { ast, dependencyFields } = await getAst({ |
|
|
|
|
query, |
|
|
|
|
model: this.model, |
|
|
|
|
view: this.viewId && (await View.get(this.viewId)), |
|
|
|
|
view: ignoreView ? null : this.viewId && (await View.get(this.viewId)), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
await this.selectObject({ |
|
|
|
@ -1836,7 +1841,12 @@ class BaseModelSqlv2 {
|
|
|
|
|
// handle if autogenerated primary key is used
|
|
|
|
|
if (ag) { |
|
|
|
|
if (!response) await this.execAndParse(query); |
|
|
|
|
response = await this.readByPk(data[ag.title]); |
|
|
|
|
response = await this.readByPk( |
|
|
|
|
data[ag.title], |
|
|
|
|
false, |
|
|
|
|
{}, |
|
|
|
|
{ ignoreView: true }, |
|
|
|
|
); |
|
|
|
|
} else if ( |
|
|
|
|
!response || |
|
|
|
|
(typeof response?.[0] !== 'object' && response?.[0] !== null) |
|
|
|
@ -1864,7 +1874,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
})) as any |
|
|
|
|
)[0].id; |
|
|
|
|
} |
|
|
|
|
response = await this.readByPk(id); |
|
|
|
|
response = await this.readByPk(id, false, {}, { ignoreView: true }); |
|
|
|
|
} else { |
|
|
|
|
response = data; |
|
|
|
|
} |
|
|
|
@ -1873,6 +1883,9 @@ class BaseModelSqlv2 {
|
|
|
|
|
Array.isArray(response) |
|
|
|
|
? response?.[0]?.[ai.title] |
|
|
|
|
: response?.[ai.title], |
|
|
|
|
false, |
|
|
|
|
{}, |
|
|
|
|
{ ignoreView: true }, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1889,7 +1902,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
let trx: Transaction = _trx; |
|
|
|
|
try { |
|
|
|
|
// retrieve data for handling params in hook
|
|
|
|
|
const data = await this.readByPk(id); |
|
|
|
|
const data = await this.readByPk(id, false, {}, { ignoreView: true }); |
|
|
|
|
await this.beforeDelete(id, trx, cookie); |
|
|
|
|
|
|
|
|
|
const execQueries: ((trx: Transaction) => Promise<any>)[] = []; |
|
|
|
@ -2018,7 +2031,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
|
|
|
|
|
await this.beforeUpdate(data, trx, cookie); |
|
|
|
|
|
|
|
|
|
const prevData = await this.readByPk(id); |
|
|
|
|
const prevData = await this.readByPk(id, false, {}, { ignoreView: true }); |
|
|
|
|
|
|
|
|
|
const query = this.dbDriver(this.tnPath) |
|
|
|
|
.update(updateObj) |
|
|
|
@ -2026,7 +2039,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
|
|
|
|
|
await this.execAndParse(query); |
|
|
|
|
|
|
|
|
|
const newData = await this.readByPk(id); |
|
|
|
|
const newData = await this.readByPk(id, false, {}, { ignoreView: true }); |
|
|
|
|
await this.afterUpdate(prevData, newData, trx, cookie, updateObj); |
|
|
|
|
return newData; |
|
|
|
|
} catch (e) { |
|
|
|
@ -2210,7 +2223,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
})) as any |
|
|
|
|
).rows[0].id; |
|
|
|
|
} |
|
|
|
|
response = await this.readByPk(id); |
|
|
|
|
response = await this.readByPk(id, false, {}, { ignoreView: true }); |
|
|
|
|
} else { |
|
|
|
|
response = data; |
|
|
|
|
} |
|
|
|
@ -2478,7 +2491,9 @@ class BaseModelSqlv2 {
|
|
|
|
|
|
|
|
|
|
if (!raw) { |
|
|
|
|
for (const pkValues of updatePkValues) { |
|
|
|
|
newData.push(await this.readByPk(pkValues)); |
|
|
|
|
newData.push( |
|
|
|
|
await this.readByPk(pkValues, false, {}, { ignoreView: true }), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2570,7 +2585,9 @@ class BaseModelSqlv2 {
|
|
|
|
|
// pk not specified - bypass
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
deleted.push(await this.readByPk(pkValues)); |
|
|
|
|
deleted.push( |
|
|
|
|
await this.readByPk(pkValues, false, {}, { ignoreView: true }), |
|
|
|
|
); |
|
|
|
|
res.push(d); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -3227,7 +3244,12 @@ class BaseModelSqlv2 {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const response = await this.readByPk(rowId); |
|
|
|
|
const response = await this.readByPk( |
|
|
|
|
rowId, |
|
|
|
|
false, |
|
|
|
|
{}, |
|
|
|
|
{ ignoreView: true }, |
|
|
|
|
); |
|
|
|
|
await this.afterInsert(response, this.dbDriver, cookie); |
|
|
|
|
await this.afterAddChild(rowId, childId, cookie); |
|
|
|
|
} |
|
|
|
@ -3276,7 +3298,12 @@ class BaseModelSqlv2 {
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
const prevData = await this.readByPk(rowId); |
|
|
|
|
const prevData = await this.readByPk( |
|
|
|
|
rowId, |
|
|
|
|
false, |
|
|
|
|
{}, |
|
|
|
|
{ ignoreView: true }, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
switch (colOptions.type) { |
|
|
|
|
case RelationTypes.MANY_TO_MANY: |
|
|
|
@ -3329,7 +3356,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const newData = await this.readByPk(rowId); |
|
|
|
|
const newData = await this.readByPk(rowId, false, {}, { ignoreView: true }); |
|
|
|
|
await this.afterUpdate(prevData, newData, this.dbDriver, cookie); |
|
|
|
|
await this.afterRemoveChild(rowId, childId, cookie); |
|
|
|
|
} |
|
|
|
|