Doctrine 2 - 从数据库中删除对象,但保留实体数据

时间:2014-04-07 08:30:02

标签: doctrine-orm

有没有办法从数据库中删除记录,但是将数据保存在实体对象中?我需要以后能够重新插入这些分离的实体。我应该直接在UnitOfWork上工作吗?谢谢。

1 个答案:

答案 0 :(得分:1)

我不确定你在问什么,但这看起来像是学说的基本行为

$student = new Student();
$student->setName("John doe");

$this->em->persist($student);
$this->em->flush();

$this->printEntity($student);
$this->em->remove($student);
$this->em->flush();
$this->printEntity($student);

这将打印出来:

Student - id : "1", name : "John doe"

Student - id : "", name : "John doe"

行已从数据库中删除,但您的实体仍然填充了其他数据。