txu-105: fix model lookups (#8386)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / uitest-workspaces (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2025-03-30 13:05:39 +04:00 committed by GitHub
parent d428316dfe
commit 9475b55489
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -925,10 +925,10 @@ abstract class PostgresAdapterBase implements DbAdapter {
const res = this.getLookupValue(modelJoin.path, lookup)
if (res === undefined) continue
const { obj, key } = res
const val = this.getModelLookupValue<T>(doc, modelJoin, simpleJoins)
const val = this.getModelLookupValue<T>(doc, modelJoin, [...simpleJoins, ...modelJoins])
if (val !== undefined && modelJoin.toClass !== undefined) {
const res = this.modelDb.findAllSync(modelJoin.toClass, {
[modelJoin.toField]: (doc as any)[modelJoin.fromField]
[modelJoin.toField]: val
})
obj[key] = modelJoin.isReverse ? res : res[0]
}
@ -972,11 +972,11 @@ abstract class PostgresAdapterBase implements DbAdapter {
}
}
private getModelLookupValue<T extends Doc>(doc: WithLookup<T>, join: JoinProps, simpleJoins: JoinProps[]): any {
private getModelLookupValue<T extends Doc>(doc: WithLookup<T>, join: JoinProps, otherJoins: JoinProps[]): any {
if (join.fromAlias.startsWith('lookup_')) {
const simple = simpleJoins.find((j) => j.toAlias === join.fromAlias)
if (simple !== undefined) {
const val = this.getLookupValue(simple.path, doc.$lookup ?? {})
const other = otherJoins.find((j) => j.toAlias === join.fromAlias)
if (other !== undefined) {
const val = this.getLookupValue(other.path, doc.$lookup ?? {})
if (val !== undefined) {
const data = val.obj[val.key]
return data[join.fromField]