Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3165

one to zero or one with identity through foreign entity

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      <?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)

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Andries Seutens
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: