0
上下文是使用Doctrine2的Symfony2項目(2.0.23)。保存主要實體時,Doctrine2重新初始化相關實體(一對一)
我有一對一的關係Website
候選人實體。當創建一個新的候選I設置Website
實體是這樣的:
Candidate.php:
<?php
use MyProject\Bundle\CoreBundle\Entity\Website;
public function initialize(Website $website)
{
$this->setWebsite($website);
的一對一的關係,聲明如下:
<?php
/**
* @var Website $website
*
* @ORM\OneToOne(targetEntity="Website")
* @ORM\JoinColumn(name="Website", referencedColumnName="Code")
*/
private $website;
一切正常本地。但在測試及生產服務器,與給定網站創建一個新的候選人時,有時相關的實體與堅持和沖洗的主要Candidate
實體正當默認值更新,這裏是MySQL日誌:
/*!*/;
# at 11400207
#130628 9:26:32 server id 1 end_log_pos 11400399 Query thread_id=53611133 exec_time=0 error_code=0
SET TIMESTAMP=1372404392/*!*/;
UPDATE website SET Name = NULL, bEnabled = NULL ... WHERE Id = 2 AND Code = 2000
我堅持與FOSUserBundle的方法:
<?php
/**
* Updates a user.
*
* @param UserInterface $user
* @param Boolean $andFlush Whether to flush the changes (default true)
*/
public function updateUser(UserInterface $user, $andFlush = true)
{
$this->updateCanonicalFields($user);
$this->updatePassword($user);
$this->em->persist($user);
if ($andFlush) {
$this->em->flush();
}
}
我不明白爲什麼。真奇怪的是,它只是偶爾發生,而且它是安靜的,不可預知的。
任何建議或提示將受到歡迎...謝謝。
PS:原則元數據緩存已停用。
編輯1:添加persist,請注意,這是通過FormHandler服務調用的。
你確定你總是堅持$網站對象befor沖洗? – Hast
你如何堅持你的實體? – nifr
@Hast:網站不必更新,它只是附加到「Candidate」實體。 – COil