mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-3165: one to zero or one with identity through foreign entity #3924
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jun 13, 2014).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user andriesss:
The relation between user and address is one to zero or one. When a record exists on both sides, everything goes fine. When the right side (address) does not have a relevant record, calling $user->getAddress(); always returns an instance. Calling a method on that instance results in an exception:
Fatal error: Uncaught exception 'Doctrine\ORM\EntityNotFoundException' with message 'Entity of type 'Address' was not found.' in doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php on line 176
Expected behaviour:
$user->getAddress() should return NULL when the right side is empty.
NOTES:
Mind that the address is identified through a foreign entity (User)
@felipyamorim commented on GitHub (Dec 22, 2016):
+1
@elisavet1 commented on GitHub (Jun 8, 2018):
Did anyone found the solution for this?
@ferran294 commented on GitHub (Oct 4, 2018):
Any solution to this?
@ferran294 commented on GitHub (Oct 5, 2018):
Ok, I just have made this work. You should create your relation one to one with EAGER load so Doctrine searches in the database with a JOIN this relation. With the by default LAZY load of Doctrine the entities are not found when trying to be found with an exact WHERE clause when accessing to the object. So the structure you should define would be like this: