From 9db09f83cb253fe5e603527a77d5ce270162299a Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sun, 30 Aug 2020 18:56:27 +0200 Subject: [PATCH] Fix ManyThroughModelRelation eagerloading --- src/db/ModelQuery.ts | 2 +- src/db/ModelRelation.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/db/ModelQuery.ts b/src/db/ModelQuery.ts index e190edd..ff0d386 100644 --- a/src/db/ModelQuery.ts +++ b/src/db/ModelQuery.ts @@ -176,7 +176,7 @@ export default class ModelQuery { if (this._pivot) { const obj: any = {}; for (const field of this._pivot) { - obj[field] = result[field]; + obj[field] = result[field.split('.')[1]]; } models.pivot!.push(obj); } diff --git a/src/db/ModelRelation.ts b/src/db/ModelRelation.ts index 76ed0f0..027f178 100644 --- a/src/db/ModelRelation.ts +++ b/src/db/ModelRelation.ts @@ -208,8 +208,8 @@ export class ManyThroughModelRelation extends public async populate(models: ModelQueryResult): Promise { const ids = models.pivot! - .filter(p => p[this.dbProperties.localPivotKey] === this.getModelID()) - .map(p => p[this.dbProperties.foreignPivotKey]); + .filter(p => p[`pivot.${this.dbProperties.localPivotKey}`] === this.getModelID()) + .map(p => p[`pivot.${this.dbProperties.foreignPivotKey}`]); this.cachedModels = models.filter(m => ids.indexOf(m[this.dbProperties.foreignKey]) >= 0); }