ModelRelations: deduplicate recursive relations on populate()

This commit is contained in:
Alice Gaudon 2020-09-08 19:24:05 +02:00
parent 969ab18b96
commit b12d104c78

View File

@ -222,7 +222,7 @@ export class RecursiveModelRelation<M extends Model> extends ManyModelRelation<M
this.cachedModels.push(...models.filter(model =>
!this.cachedModels!.find(cached => cached.equals(model)) &&
this.cachedModels!.find(cached => cached[this.dbProperties.localKey] === model[this.dbProperties.foreignKey])
));
).reduce((array: M[], val) => array.find(v => v.equals(val)) ? array : [...array, val], []));
} while (count !== this.cachedModels.length);
if (this.reverse) this.cachedModels!.reverse();