Details
-
Type:
Sub-task
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.1.2
-
Fix Version/s: None
-
Component/s: ORM
-
Security Level: All
-
Labels:None
Description
/**
* @ORM\Entity
*/
class Top
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToOne(targetEntity="LevelOne", orphanRemoval="true", cascade={"persist", "remove"})
*/
protected $levelOne;
public function getId()
{
return $this->id;
}
public function setLevelOne(LevelOne $levelOne)
{
$this->levelOne = $levelOne;
}
public function getLevelOne()
{
return $this->levelOne;
}
}
/**
* @ORM\Entity
*/
class LevelOne
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToOne(targetEntity="LevelTwo", orphanRemoval="true", cascade={"persist", "remove"})
*/
protected $levelTwo;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
public function setLevelTwo(LevelTwo $levelTwo)
{
$this->levelTwo = $levelTwo;
}
public function getLevelTwo()
{
return $this->levelTwo;
}
}
/**
* @ORM\Entity
*/
class LevelTwo
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
}
trying to clone objects
$top = new Top(); $top->setLevelOne(new LevelOne()); $top->getLevelOne()->setLevelTwo(new LevelTwo()); $this->em->persist($top); $this->em->flush(); $newTop = new Top(); $newTop->setLevelOne(clone $top->getLevelOne()); $newTop->getLevelOne()->setId(null); $newTop->getLevelOne()->getLevelTwo()->setId(null); var_dump($newTop->getLevelOne()->getId()); var_dump($newTop->getLevelOne()->getLevelTwo()->getId()); $this->em->persist($newTop); $this->em->flush();
the output is:
NULL
NULL
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'UNIQ_82A72CD0778BC57F'
(it duplicates level two entity)
I worked for a while with entities, in a certain set of entity properties it completely persisted into database, but without relation between level one and level two.