Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializing a relation can result in the loss of pending changes #486

Closed
followben opened this issue Apr 17, 2020 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@followben
Copy link
Contributor

followben commented Apr 17, 2020

Describe the bug
Lazily populating a bidirectional relation inadvertently writes any pending changes for the parent (and any onward relations) to the EntityManager's originalEntityData map. When the resulting UnitOfWork is committed, those changes are omitted from the changeSet and never written to the DB.

To Reproduce
Steps to reproduce the behavior:

  1. Fetch an entity instance but don't populate any bidirectional relations
  2. Change a property on the fetched instance (e.g. a scalar value)
  3. Initialize a bidirectional relation and change it (e.g. add a new instance to a Collection)
  4. Call em.persistAndFlush()

Expected behavior
Both changes are persisted to the database.

Actual behavior
Only the 2nd change, after the relation init(), is persisted.

Versions

Dependency Version
node 13.10.1
typescript 3.8.3
mikro-orm 3.6.7
pg 7.18.2
@B4nan
Copy link
Member

B4nan commented Apr 17, 2020

Thanks for the repro, appreciated!

@B4nan B4nan closed this as completed in 40830d5 Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants