Skip to content

Replacing a one-to-one relation with a new entity sets the relation to null until refetched. #2806

@jamesmeneghello

Description

@jamesmeneghello

Describe the bug

Fetch an existing entity (A) with an existing 1-1 relation attached (B), where A is the owner with orphanRemoval set. Replace the 1-1 relation (a.some_b = em.create(B, {...})) and the UoW generates three changes:

  1. Create new B
  2. Update A setting a.some_b to undefined
  3. Delete old B

Since a.some_b is set to undefined, the new B is created but the relation on A is not populated - accessing a.some_b at this point is undefined. Presumably #2 should hold some kind of reference to new B so that the new relation is written.

Expected behavior

Expected a.some_b to be the new instance of B.

Versions

Dependency Version
node 16
typescript 4.4.4
mikro-orm 5.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions