Skip to content

Commit

Permalink
fix(orm): make sure getJoin operates on existing join model
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Feb 2, 2024
1 parent e6e6faa commit 03b2428
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/orm/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,11 @@ export class BaseQuery<T extends OrmEntity> {
return new JoinDatabaseQuery(c[1].classSchema, c[1], c[0]);
}

getJoin<K extends keyof ReferenceFields<T>, ENTITY extends OrmEntity = FindEntity<T[K]>>(field: K): BaseQuery<ENTITY> {
getJoin<K extends keyof ReferenceFields<T>, ENTITY extends OrmEntity = FindEntity<T[K]>>(field: K): JoinDatabaseQuery<ENTITY, this> {
for (const join of this.model.joins) {
if (join.propertySchema.name === field) return join.query;
if (join.propertySchema.name === field) return new JoinDatabaseQuery(join.query.classSchema, join.query, this);
}
throw new Error(`No join fo reference ${String(field)} added.`);
throw new Error(`No join for reference ${String(field)} added.`);
}

/**
Expand Down Expand Up @@ -1022,6 +1022,7 @@ export class JoinDatabaseQuery<T extends OrmEntity, PARENT extends BaseQuery<any
public parentQuery?: PARENT
) {
super(classSchema);
if (query) this.model = query.model;
}

clone(parentQuery?: PARENT): this {
Expand Down

0 comments on commit 03b2428

Please sign in to comment.