Skip to content

Commit

Permalink
fix(core): do not trigger global context validation from repositories
Browse files Browse the repository at this point in the history
Closes #2778
  • Loading branch information
B4nan committed Feb 17, 2022
1 parent e39ef5b commit f651865
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/entity/EntityRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class EntityRepository<T extends AnyEntity<T>> {
}

protected get em(): EntityManager {
return this._em.getContext();
return this._em.getContext(false);
}

}
2 changes: 1 addition & 1 deletion packages/knex/src/SqlEntityRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class SqlEntityRepository<T> extends EntityRepository<T> {
}

protected get em(): SqlEntityManager {
return this._em.getContext() as SqlEntityManager;
return this._em.getContext(false) as SqlEntityManager;
}

}
2 changes: 1 addition & 1 deletion packages/mongodb/src/MongoEntityRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MongoEntityRepository<T> extends EntityRepository<T> {
}

protected get em(): MongoEntityManager {
return this._em.getContext() as MongoEntityManager;
return this._em.getContext(false) as MongoEntityManager;
}

}
13 changes: 13 additions & 0 deletions tests/EntityManager.postgre.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,19 @@ describe('EntityManagerPostgre', () => {
orm.config.set('allowGlobalContext', true);
});

test('working with global identity map will not throw if disableIdentityMap is used', async () => {
orm.config.set('allowGlobalContext', false);

await orm.em.nativeInsert(FooBar2, { name: 'bar 1' });
const res1 = await orm.em.getRepository(FooBar2).find({}, { disableIdentityMap: true });
expect(res1).toHaveLength(1);

const res2 = await orm.em.find(FooBar2, {}, { disableIdentityMap: true });
expect(res2).toHaveLength(1);

orm.config.set('allowGlobalContext', true);
});

test('Collection.init() returns Loaded type', async () => {
await createBooksWithTags();
const a = await orm.em.findOneOrFail(Author2, { email: 'snow@wall.st' });
Expand Down

0 comments on commit f651865

Please sign in to comment.