[DDC-1895] update an entity with an ID column which is a relation instead of a normal field Created: 27/Jun/12 Updated: 05/Jul/12 Resolved: 05/Jul/12 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | Mapping Drivers |
| Affects Version/s: | Git Master |
| Fix Version/s: | 2.2.3, 2.3 |
| Security Level: | All |
| Type: | Bug | Priority: | Major |
| Reporter: | Bart van den Burg | Assignee: | Benjamin Eberlei |
| Resolution: | Fixed | Votes: | 0 |
| 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 |
| Comments |
| Comment by Benjamin Eberlei [ 05/Jul/12 ] |
|
Fixed |