I am using Symfony 2.8 with some bundles installed
knplabs/doctrine-behaviors
-> this is for softdelete
a2lix/translation-form-bundle
-> this is for translation
CLASS Room
namespace AppBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
/**
* Room
* @ORM\Table(name="room")
* @ORM\Entity(repositoryClass="AppBundle\Repository\RoomRepository")
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class Room {
use ORMBehaviors\Translatable\Translatable;
use SoftDeleteableEntity;
private $id;
private $price;
public function getId() {
return $this->id;
}
public function setPrice($price) {
$this->price = $price;
return $this;
}
public function getPrice() {
return $this->price;
}
public function __clone() {
$this->id = null;
}
}
CLASS Room Translation
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use Symfony\Component\Validator\Constraints as Assert;
class RoomTranslation {
use ORMBehaviors\Translatable\Translation;
private $name;
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
}
And now on Controller i need to clone a room object with softdelete the original one
my action like that
public function CloneAction(Request $request) {
$em = $this->getDoctrine()->getEntityManager();
$room = $em->getRepository('AppBundle:Room')->findOneById(1);
$new = clone $room;
$new->setPrice(500);
foreach ($room->getTranslations() as $translation) {
$new->addTranslation(clone $translation);
}
$em->remove($room);
$em->persist($new);
$em->flush();
}
When i run this code i got this error
Detached entity AppBundle\Entity\RoomTranslation@00000000293cdfa500000000bfea438f cannot be removed
Any idea why i got this error ?