Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: Git Master
-
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
Fixed