Fix ManyThroughModelRelation eagerloading
This commit is contained in:
parent
fae5c68cd0
commit
9db09f83cb
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user