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) {
|
if (this._pivot) {
|
||||||
const obj: any = {};
|
const obj: any = {};
|
||||||
for (const field of this._pivot) {
|
for (const field of this._pivot) {
|
||||||
obj[field] = result[field];
|
obj[field] = result[field.split('.')[1]];
|
||||||
}
|
}
|
||||||
models.pivot!.push(obj);
|
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> {
|
public async populate(models: ModelQueryResult<O>): Promise<void> {
|
||||||
const ids = models.pivot!
|
const ids = models.pivot!
|
||||||
.filter(p => p[this.dbProperties.localPivotKey] === this.getModelID())
|
.filter(p => p[`pivot.${this.dbProperties.localPivotKey}`] === this.getModelID())
|
||||||
.map(p => p[this.dbProperties.foreignPivotKey]);
|
.map(p => p[`pivot.${this.dbProperties.foreignPivotKey}`]);
|
||||||
this.cachedModels = models.filter(m => ids.indexOf(m[this.dbProperties.foreignKey]) >= 0);
|
this.cachedModels = models.filter(m => ids.indexOf(m[this.dbProperties.foreignKey]) >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user