RobinCK / typeorm-fixtures

:pill: Fixtures loader for typeorm 🇺🇦
https://robinck.github.io/typeorm-fixtures/
MIT License
566 stars 45 forks source link

Prevent fixture from being loaded in processor #75

Closed Nosfistis closed 3 years ago

Nosfistis commented 5 years ago

I have some entities being inserted via triggers in DB, and having a unique index (independent of the PK). Using fixtures, it's not possible to know what the row id will be in before, but I would like to use it later on to append relations on those entities.

So far I have tried creating a load processor to read the id and perform the update there, using the unique index columns. The update is done, but, I get a weird error afterwards:

Fail fixture loading: Could not find any entity of type "ProjectMap" matching: {
    "where": {}
}

My preProcess function:

  async preProcess(name: string, obj: ProjectMap): Promise<ProjectMap> {
    const repository = getConnection().getRepository(ProjectMap);
    const { id } = await repository.findOneOrFail({ select: ['id'], where: { method: obj.method, resourceId: obj.resource.id } });
    obj.id = id;

    await repository.save(obj);

    return derived;
  }

I cannot find how the save fails afterwards, however perhaps I could skip the library's save by returning null?