【发布时间】:2016-09-23 14:38:30
【问题描述】:
我正在尝试创建依赖于其他实体 createDT 标记的固定装置。但是,当我使用 @prepersist 填充我的实体中的 createDT 字段时,我无法“欺骗”这些内容。我有很多实体参与其中,我想知道是否有任何方法可以暂时冻结/覆盖这个 @prepersist 只是为了加载我的装置?
我的实体都有:
/**
* Set createDT
* @ORM\PrePersist
*/
public function setCreateDT()
{
$this->createDT = new \DateTime();
return $this;
}
...我正在尝试以以下方式有条件地指定固定装置的值,与另一个实体的 createDT 进行比较:
class LoadTransactionData extends AbstractFixture implements OrderedFixtureInterface {
public function load(ObjectManager $manager) {
for ($month=1; $month <= 120; $month++) {
$transaction = new Transaction();
$date = new \DateTime();
if($date->setDate(2000 + floor($month/12),$month % 12,1) < $this->getReference('AC_1')->getCreateDT()) {
// ...get references etc and do stuff here....
} else {
// ...get references etc and do other stuff here...
}
$manager->persist($transaction);
}
$manager->flush();
}
更新:以上是最好的,但如果不可能,如果有办法延迟某些记录的持久化可能就足够了?这样,我至少可以做出一两秒的时间戳差异来进行比较
【问题讨论】:
标签: doctrine-orm symfony fixtures