Fix relation reducing mistakenly using "in" instead of indexOf >= 0

This commit is contained in:
Alice Gaudon 2020-09-10 19:11:32 +02:00
parent d3e3a86855
commit 15678e0381

View File

@ -72,7 +72,7 @@ export default abstract class ModelRelation<S extends Model, O extends Model, R
public async eagerLoad(relations: ModelRelation<S, O, R>[], subRelations: string[] = []): Promise<ModelQueryResult<O>> { public async eagerLoad(relations: ModelRelation<S, O, R>[], subRelations: string[] = []): Promise<ModelQueryResult<O>> {
const ids = relations.map(r => r.getModelID()) const ids = relations.map(r => r.getModelID())
.filter(id => id !== null && id !== undefined) .filter(id => id !== null && id !== undefined)
.reduce((array: O[], val) => val in array ? array : [...array, val], []); .reduce((array: O[], val) => array.indexOf(val) >= 0 ? array : [...array, val], []);
if (ids.length === 0) return []; if (ids.length === 0) return [];
const query = this.makeQuery(); const query = this.makeQuery();
@ -181,7 +181,7 @@ export class ManyThroughModelRelation<S extends Model, O extends Model> extends
public async eagerLoad(relations: ModelRelation<S, O, O[]>[], subRelations: string[] = []): Promise<ModelQueryResult<O>> { public async eagerLoad(relations: ModelRelation<S, O, O[]>[], subRelations: string[] = []): Promise<ModelQueryResult<O>> {
const ids = relations.map(r => r.getModelID()) const ids = relations.map(r => r.getModelID())
.reduce((array: O[], val) => val in array ? array : [...array, val], []); .reduce((array: O[], val) => array.indexOf(val) >= 0 ? array : [...array, val], []);
if (ids.length === 0) return []; if (ids.length === 0) return [];
const query = this.makeQuery(); const query = this.makeQuery();