MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / getContext

Method getContext

packages/core/src/EntityManager.ts:2615–2634  ·  view source on GitHub ↗

* Gets the EntityManager based on current transaction/request context. * @internal

(validate = true)

Source from the content-addressed store, hash-verified

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 {

Callers 15

findMethod · 0.95
streamMethod · 0.95
addFilterMethod · 0.95
setFilterParamsMethod · 0.95
getFilterParamsMethod · 0.95
setLoggerContextMethod · 0.95
getLoggerContextMethod · 0.95
setFlushModeMethod · 0.95
applyFiltersMethod · 0.95
findAndCountMethod · 0.95
findByCursorMethod · 0.95
refreshMethod · 0.95

Calls 3

getMethod · 0.65
getEntityManagerMethod · 0.45

Tested by

no test coverage detected