Open kiler129 opened 1 year ago
What if you make the entities not be readOnly: false
, and allow the parent
association to be null
able?
IMHO, with readonly: true
you should not be able to persist in the first place, or that should be a no-op
@mpdude I didn't try the null
able yet. However, it's not a no-op since otherwise you wouldn't be able to add the entity at all. A better name would probably be something akin to wrom
.
The docs eexplicitly describe that (https://www.doctrine-project.org/projects/doctrine-orm/en/2.14/reference/improving-performance.html#read-only-entities):
Read-Only allows to persist new entities of a kind and remove existing ones, they are just not considered for updates.
Oh! TIL
Bug Report
Summary
Given the following entity:
I attempted to create two instances and assign one as a parent to the other:
Current behavior
How to reproduce
The code above is a minimal example. I also tested with
ManyToOne
and the behavior is the same. Interestingly changingEntity(readOnly: true)
toEntity(readOnly: false)
doesn't affect the problem. What does thou is putting a second flush like so:Expected behavior
Entities should persist, especially given that keys for the relationship are known. I'm suspecting (thou I didn't debug as it's 3am ;)) it may try to re-persist the
$parent
after getting$child
into the cache/db, in order to fill-in the relationship.