|
|
|
@ -1711,7 +1711,8 @@ class BaseModelSqlv2 {
|
|
|
|
|
(await column.getColOptions()) as LinkToAnotherRecordColumn; |
|
|
|
|
|
|
|
|
|
if (colOptions?.type === 'hm') { |
|
|
|
|
const listLoader = new DataLoader(async (ids: string[]) => { |
|
|
|
|
const listLoader = new DataLoader( |
|
|
|
|
async (ids: string[]) => { |
|
|
|
|
if (ids.length > 1) { |
|
|
|
|
const data = await this.multipleHmList( |
|
|
|
|
{ |
|
|
|
@ -1720,7 +1721,9 @@ class BaseModelSqlv2 {
|
|
|
|
|
}, |
|
|
|
|
(listLoader as any).args, |
|
|
|
|
); |
|
|
|
|
return ids.map((id: string) => (data[id] ? data[id] : [])); |
|
|
|
|
return ids.map((id: string) => |
|
|
|
|
data[id] ? data[id] : [], |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
return [ |
|
|
|
|
await this.hmList( |
|
|
|
@ -1732,7 +1735,11 @@ class BaseModelSqlv2 {
|
|
|
|
|
), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
cache: false, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
const self: BaseModelSqlv2 = this; |
|
|
|
|
|
|
|
|
|
proto[ |
|
|
|
@ -1746,7 +1753,8 @@ class BaseModelSqlv2 {
|
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
} else if (colOptions.type === 'mm') { |
|
|
|
|
const listLoader = new DataLoader(async (ids: string[]) => { |
|
|
|
|
const listLoader = new DataLoader( |
|
|
|
|
async (ids: string[]) => { |
|
|
|
|
if (ids?.length > 1) { |
|
|
|
|
const data = await this.multipleMmList( |
|
|
|
|
{ |
|
|
|
@ -1768,7 +1776,11 @@ class BaseModelSqlv2 {
|
|
|
|
|
), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
cache: false, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const self: BaseModelSqlv2 = this; |
|
|
|
|
proto[ |
|
|
|
@ -1796,7 +1808,8 @@ class BaseModelSqlv2 {
|
|
|
|
|
// it takes individual keys and callback is invoked with an array of values and we can get the
|
|
|
|
|
// result for all those together and return the value in the same order as in the array
|
|
|
|
|
// this way all parents data extracted together
|
|
|
|
|
const readLoader = new DataLoader(async (_ids: string[]) => { |
|
|
|
|
const readLoader = new DataLoader( |
|
|
|
|
async (_ids: string[]) => { |
|
|
|
|
// handle binary(16) foreign keys
|
|
|
|
|
const ids = _ids.map((id) => { |
|
|
|
|
if (pCol.ct !== 'binary(16)') return id; |
|
|
|
@ -1843,8 +1856,14 @@ class BaseModelSqlv2 {
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const groupedList = groupBy(data, pCol.title); |
|
|
|
|
return _ids.map(async (id: string) => groupedList?.[id]?.[0]); |
|
|
|
|
}); |
|
|
|
|
return _ids.map( |
|
|
|
|
async (id: string) => groupedList?.[id]?.[0], |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
cache: false, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// defining BelongsTo read resolver method
|
|
|
|
|
proto[column.title] = async function (args?: any) { |
|
|
|
@ -4332,7 +4351,7 @@ class BaseModelSqlv2 {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async addLinks({ |
|
|
|
|
cookie: _cookie, |
|
|
|
|
cookie, |
|
|
|
|
childIds, |
|
|
|
|
colId, |
|
|
|
|
rowId, |
|
|
|
@ -4348,9 +4367,12 @@ class BaseModelSqlv2 {
|
|
|
|
|
if (!column || !isLinksOrLTAR(column)) |
|
|
|
|
NcError.notFound(`Link column ${colId} not found`); |
|
|
|
|
|
|
|
|
|
const row = await this.dbDriver(this.tnPath) |
|
|
|
|
.where(await this._wherePk(rowId)) |
|
|
|
|
.first(); |
|
|
|
|
const row = await this.readByPk( |
|
|
|
|
rowId, |
|
|
|
|
false, |
|
|
|
|
{}, |
|
|
|
|
{ ignoreView: true, getHiddenColumn: true }, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// validate rowId
|
|
|
|
|
if (!row) { |
|
|
|
@ -4554,9 +4576,16 @@ class BaseModelSqlv2 {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// const response = await this.readByPk(rowId);
|
|
|
|
|
// await this.afterInsert(response, this.dbDriver, cookie);
|
|
|
|
|
// await this.afterAddChild(rowId, childId, cookie);
|
|
|
|
|
const response = await this.readByPk( |
|
|
|
|
rowId, |
|
|
|
|
false, |
|
|
|
|
{}, |
|
|
|
|
{ ignoreView: true, getHiddenColumn: true }, |
|
|
|
|
); |
|
|
|
|
await this.afterUpdate(row, response, this.dbDriver, cookie); |
|
|
|
|
for (const childId of childIds) { |
|
|
|
|
await this.afterAddChild(rowId, childId, cookie); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async removeLinks({ |
|
|
|
|