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); }