Problem/Motivation
This is a data loss bug in the entity system but it's hard enough to hit not to be critical. Let's have this setup: $parent->reference->entity = $child
where reference
is an entity reference field and $child
is stored already in the database.
- change
$child
in any way - call the
resetCache
method on the entity storage of$child
- call
$parent->reference->referencedEntities()
. This will return$child
as it is in the database instead of the changed state.
Proposed resolution
Add EntityReferenceItem::hasEntity
much like EntityReferenceItem::hasNewEntity
and use the entity if it already is there instead of loading. This will also be a performance boost (tiny in most cases but still).
Remaining tasks
Approve, code, review, code, review, code, review etc until satisfied, commit, rejoice :D
User interface changes
None.
API changes
A new method on EntityReferenceItem.