-
-
Notifications
You must be signed in to change notification settings - Fork 611
Description
📖 I'm not sure if the current behavior is a bug, but the behavior is not obvious to me.
Describe the bug
I have an entity with a 1:M relation. For this relation I'm set the orphanRemoval: true option. If I delete an item from a collection and then call the em.persistAndFlush method in the transaction, then the items will not be deleted from the database.
entity.children.removeAll();
await orm.em.transactional(async (em) => {
// Works fine
// entity.children.removeAll();
// Simplified code. There are several operations.
await em.persistAndFlush(entity);
});📖 I have a repository that makes it easy to reproduce the problem:
https://github.com/mrmlnc/mikro-orm-collection-transaction-issue
To Reproduce
Steps to reproduce the behavior:
git clone https://github.com/mrmlnc/mikro-orm-collection-transaction-issuenpm cinpm run start
Expected behavior
Items removed from the collection will be removed from the database.
Additional context
I found that the problem disappears if you do a deletion inside a transaction. I think the current problem is related to copying the current state into the fork for transaction.
Versions
| Dependency | Version |
|---|---|
| node | 16.16.0 |
| typescript | 4.7.4 |
| mikro-orm | 5.3.0 |
| better-sqlite | 5.3.0 |