Fix ManyThroughModelRelation eagerloading

This commit is contained in:
Alice Gaudon 2020-08-30 18:56:27 +02:00
parent fae5c68cd0
commit 9db09f83cb
2 changed files with 3 additions and 3 deletions

View File

@ -176,7 +176,7 @@ export default class ModelQuery<M extends Model> {
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);
}

View File

@ -208,8 +208,8 @@ export class ManyThroughModelRelation<S extends Model, O extends Model> extends
public async populate(models: ModelQueryResult<O>): Promise<void> {
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);
}