Skip to content

Commit

Permalink
fix(typeorm-common): update repository to get entityManager from opti…
Browse files Browse the repository at this point in the history
…ons when needed
  • Loading branch information
concepta-thiago committed Apr 22, 2024
1 parent 5ef049f commit dff7613
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/typeorm-common/src/proxies/entity-manager.proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { TransactionProxy } from './transaction.proxy';
export class EntityManagerProxy {
constructor(private _entityManager: EntityManager) {}

entityManager(options?: EntityManagerOptionInterface) {
return options?.entityManager ?? this._entityManager;
entityManager() {
return this._entityManager;
}

repository<T extends ObjectLiteral>(
Expand All @@ -17,8 +17,11 @@ export class EntityManagerProxy {
): Repository<T> {
if (options?.transaction) {
return options.transaction.repository(repository);
} else if (this.entityManager(options) !== this._entityManager) {
return this._entityManager.withRepository<T, Repository<T>>(repository);
} else if (
options?.entityManager &&
options?.entityManager !== repository.manager
) {
return options.entityManager.withRepository<T, Repository<T>>(repository);
} else {
return repository;
}
Expand Down

0 comments on commit dff7613

Please sign in to comment.