Can someone explain when exactly implicit transactions occur? #5466
-
I understand the "unit of work" model, or at least I think I do, but the docs aren't clear on how different API methods map onto transactions. For example, if I want to create new DB records, I can do
But I can also do
It's unclear to me that the second approach results in records being created within an implicit transaction. Likewise, using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Nope, you need explicit transaction demarcation for that. https://mikro-orm.io/docs/transactions#approach-2-explicitly With that approach, you no longer need the explicit flush, as it is called automatically after the callback (as well as via explicit |
Beta Was this translation helpful? Give feedback.
em.create
is sync method, it does the same as your previous example - create entity instance (via constructor) and persist it. its the flush call that does things (and you need to await that one instead of the create call). that's described hereNope, you need explicit transaction demarcation for that.
https://mikro-orm.io/docs/transactions#approach-2-explicitly
With that approach, you no longer need the explicit flush, as it is called automatically after the callback (as well as via explicit
em.commit()
).