Skip to content

Loading…

DDC-3165: one to zero or one with identity through foreign entity #3945

Open
doctrinebot opened this Issue · 0 comments

2 participants

@doctrinebot

Jira issue originally created by user andriesss:

<?php

/****
 * @Entity
 */
class User
{
    /**** 
     * @Id @Column(type="integer") 
     * @GeneratedValue 
     */
    private $id;

    /****
     * @ORM\OneToOne(targetEntity="Address")
     *
     * @var Address
     */
    private $address;

    public function getAddress()
    {
        return $this->address;
    }
}

/****
 * @Entity
 */
class Address
{
    /****
     * @Id @OneToOne(targetEntity="User") 
     */
    private $user;

    public function foo()
    {}
}


?>

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)

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.