1

我正在使用安装了一些捆绑包的 Symfony 2.8

knplabs/doctrine-behaviors-> 这是用于软删除

a2lix/translation-form-bundle-> 这是翻译

教室

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;
}
}

教室翻译

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;
}

}

现在在控制器上,我需要使用软删除原始对象克隆一个房间对象

我这样的行为

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();
}

当我运行此代码时,出现此错误

Detached entity AppBundle\Entity\RoomTranslation@00000000293cdfa500000000bfea438f cannot be removed

知道为什么我会收到此错误吗?

4

0 回答 0