From b12d104c7818c75a4a1fc95a1ccf426d0cd1e3d5 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Tue, 8 Sep 2020 19:24:05 +0200 Subject: [PATCH] ModelRelations: deduplicate recursive relations on populate() --- src/db/ModelRelation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/ModelRelation.ts b/src/db/ModelRelation.ts index 1ffb0ff..6a1c54b 100644 --- a/src/db/ModelRelation.ts +++ b/src/db/ModelRelation.ts @@ -222,7 +222,7 @@ export class RecursiveModelRelation extends ManyModelRelation !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();