* Gets the EntityManager based on current transaction/request context. * @internal
(validate = true)
| 2613 | * @internal |
| 2614 | */ |
| 2615 | getContext(validate = true): this { |
| 2616 | if (!this.#useContext) { |
| 2617 | return this; |
| 2618 | } |
| 2619 | |
| 2620 | let em = TransactionContext.getEntityManager(this.name) as this; // prefer the tx context |
| 2621 | |
| 2622 | if (em) { |
| 2623 | return em; |
| 2624 | } |
| 2625 | |
| 2626 | // no explicit tx started |
| 2627 | em = (this.config.get('context')(this.name) as this) ?? this; |
| 2628 | |
| 2629 | if (validate && !this.config.get('allowGlobalContext') && em.global) { |
| 2630 | throw ValidationError.cannotUseGlobalContext(); |
| 2631 | } |
| 2632 | |
| 2633 | return em; |
| 2634 | } |
| 2635 | |
| 2636 | /** Gets the EventManager instance used by this EntityManager. */ |
| 2637 | getEventManager(): EventManager { |
no test coverage detected