This commit is contained in:
Adria Navarro 2024-10-28 13:53:44 +01:00
parent 097a7f8aae
commit d944e3a8f9
1 changed files with 2 additions and 10 deletions

View File

@ -443,7 +443,6 @@ export class ExternalRequest<T extends Operation> {
rows: Row[] rows: Row[]
isMany: boolean isMany: boolean
tableId: string tableId: string
field: string
} }
> = {} > = {}
@ -478,10 +477,7 @@ export class ExternalRequest<T extends Operation> {
"Unable to lookup relationships - undefined column properties." "Unable to lookup relationships - undefined column properties."
) )
} }
const { tableName: relatedTableName } =
breakExternalTableId(relatedTableId)
// @ts-ignore
const linkPrimaryKey = this.tables[relatedTableName].primary[0]
if (!lookupField || !row?.[lookupField] == null) { if (!lookupField || !row?.[lookupField] == null) {
continue continue
} }
@ -506,15 +502,11 @@ export class ExternalRequest<T extends Operation> {
!Array.isArray(response) || isKnexEmptyReadResponse(response) !Array.isArray(response) || isKnexEmptyReadResponse(response)
? [] ? []
: response : response
const storeTo = isManyToMany(field)
? field.throughFrom || linkPrimaryKey
: fieldName
related[this.getLookupRelationsKey(field)] = { related[this.getLookupRelationsKey(field)] = {
rows, rows,
isMany: isManyToMany(field), isMany: isManyToMany(field),
tableId: relatedTableId, tableId: relatedTableId,
field: storeTo,
} }
} }
return related return related
@ -602,7 +594,7 @@ export class ExternalRequest<T extends Operation> {
} }
} }
// finally cleanup anything that needs to be removed // finally cleanup anything that needs to be removed
for (let { isMany, rows, tableId, field } of Object.values(related)) { for (const [field, { isMany, rows, tableId }] of Object.entries(related)) {
const table: Table | undefined = this.getTable(tableId) const table: Table | undefined = this.getTable(tableId)
// if it's not the foreign key skip it, nothing to do // if it's not the foreign key skip it, nothing to do
if ( if (