From e95f5c93485fe0b016bbb8bdcf6a5515e7b7fdbe Mon Sep 17 00:00:00 2001 From: Artem Derevnjuk Date: Sun, 30 Jan 2022 15:27:23 +0300 Subject: [PATCH] refactor(mikro-orm): ensure backward compatibility with v4.x and add support for v5.x --- .../src/interceptors/TransactionalInterceptor.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/orm/mikro-orm/src/interceptors/TransactionalInterceptor.ts b/packages/orm/mikro-orm/src/interceptors/TransactionalInterceptor.ts index 8816f679374..1a4ad39071d 100644 --- a/packages/orm/mikro-orm/src/interceptors/TransactionalInterceptor.ts +++ b/packages/orm/mikro-orm/src/interceptors/TransactionalInterceptor.ts @@ -57,7 +57,21 @@ export class TransactionalInterceptor implements InterceptorMethods { ); } - const em = orm.em.fork(true, true); + /** + * The fork method signature has been changed since v5.x, + * which might lead to unexpected behavior while using the @Transactional() decorator. + * + * ```diff + * - fork(clear = true, useContext = false): D[typeof EntityManagerType] + * + fork(options: ForkOptions = {}): D[typeof EntityManagerType] { + * ``` + * + * To ensure backward compatibility with v4.x and add support for v5.x, provided the following workaround: + */ + const em = (orm.em.fork as ( + clearOrForkOptions?: boolean | {clear?: boolean; useContext?: boolean}, + useContext?: boolean + ) => EntityManager)({clear: true, useContext: true}, true); ctx.set(em.name, em);