Skip to content

Commit

Permalink
refactor(mikro-orm): ensure backward compatibility with v4.x and add …
Browse files Browse the repository at this point in the history
…support for v5.x
  • Loading branch information
derevnjuk committed Jan 30, 2022
1 parent 0e3f587 commit e95f5c9
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e95f5c9

Please sign in to comment.