Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1895

update an entity with an ID column which is a relation instead of a normal field

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Git Master
    • Fix Version/s: 2.2.3, 2.3
    • Component/s: Mapping Drivers
    • Security Level: All
    • Labels:
      None

      Description

      I got this error when trying to update an entity with an ID column which is a relation instead of a normal field: https://gist.github.com/3399c0ad5e0a44a29f98

      Here is the relevant mapping:

      <?php
      
      namespace Roompot\TRSBundle\Entity;
      
      use Doctrine\ORM\Mapping as ORM;
      use Samson\Bundle\TRSBundle\Entity\Registrar;
      
      /**
       * @ORM\Entity
       */
      class RegistrarDepartmentMapping
      {
          /**
           * @ORM\ManyToOne(targetEntity="RoompotRegistrar")
           * @ORM\JoinColumn(referencedColumnName="person_id")
           * @ORM\Id
           */
          private $registrar;
      
          /**
           * @ORM\ManyToOne(targetEntity="Department")
           * @ORM\Id
           */
          private $department;
      
          /**
           * @ORM\Column(type="boolean")
           */
          private $head = false;
      
          public function getRegistrar()
          {
              return $this->registrar;
          }
      
          public function setRegistrar(Registrar $registrar)
          {
              if (null !== $this->registrar) {
                  throw new \RuntimeException('Cannot change registrar! Remove this entity and create a new one');
              }
              $this->registrar = $registrar;
          }
      
          public function getDepartment()
          {
              if (null !== $this->registrar) {
                  throw new \RuntimeException('Cannot change department! Remove this entity and create a new one');
              }
              return $this->department;
          }
      
          public function setDepartment(Department $department)
          {
              $this->department = $department;
          }
      
          public function isHead()
          {
              return $this->head;
          }
      
          public function setHead($head)
          {
              $this->head = $head;
          }
      }
      
      <?php
      
      namespace Roompot\TRSBundle\Entity;
      
      use Doctrine\ORM\Mapping as ORM;
      use Samson\Bundle\TRSBundle\Entity\Registrar;
      
      /**
       * @ORM\Entity
       */
      class RoompotRegistrar extends Registrar
      {
          [...]
      }
      
      <?php
      
      namespace Samson\Bundle\TRSBundle\Entity;
      
      use Samson\Bundle\AddressBookBundle\Entity\Person;
      use Doctrine\ORM\Mapping as ORM;
      
      /**
       * @ORM\Entity 
       * @ORM\InheritanceType("SINGLE_TABLE")
       * @ORM\DiscriminatorColumn(name="discr", type="string")
       */
      abstract class Registrar
      {
          /**
           * @ORM\Id
           * @ORM\OneToOne(targetEntity="Samson\Bundle\AddressBookBundle\Entity\Person", cascade={"persist"})
           * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
           */
          private $person;
      
          [...]
      }
      
      <?php
      
      namespace Samson\Bundle\AddressBookBundle\Entity;
      
      use Doctrine\ORM\Mapping as ORM;
      
      /**
       * @ORM\Entity(repositoryClass="Samson\Bundle\AddressBookBundle\Entity\PersonRepository")
       */
      class Person implements [...]
      {
          /**
           * @ORM\Column(type="integer")
           * @ORM\Id
           * @ORM\GeneratedValue
           */
          private $id;
      
          [...]
      }
      

      I was able to fix the error by updating BasicEntityPersister: https://github.com/SamsonIT/doctrine2/compare/fetching_id_column_if_relation

        Activity

        Bart van den Burg created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.2.3 [ 10196 ]
        Fix Version/s 2.3 [ 10185 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13804 ] jira-feedback [ 15396 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15396 ] jira-feedback2 [ 17260 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17260 ] jira-feedback3 [ 19516 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Bart van den Burg
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: