我有兩個實體,View
和Location
主義不會持續增加實體關係
每個View
可以有一個Location
。
在我看來,我這樣有:
class View
{
//..... Other Stuff.....
/**
* @ManyToOne(targetEntity="Location", inversedBy="views")
**/
private $location;
//...setters and getters....
public function setLocation($location){
$this->location = $location;
}
}
,然後我的位置
class Location
{
//.....other stuff.....
/**
* @OneToMany(targetEntity="View", mappedBy="location")
**/
private $views;
public function __construct() {
$this->created = $this->updated = new \DateTime("now");
$this->views = new \Doctrine\Common\Collections\ArrayCollection();
}
// .... Getters and Setters ....
}
但是當我嘗試這樣做:
<?php
$this->pageview = $this->em->getRepository('Entities\View')->find(1);
$this->location = $this->em->getRepository('Entities\Location')->find(1);
$this->pageview->setLocation($this->location);
$this->em->persist($this->pageview);
$this->em->flush();
?>
甚至當我創建新實體:
<?php
$pv = new Entities\Pageview;
$lc = new Entities\Location;
$this->em->persist($lc);
$this->em->flush();
$pv->setLocation($lc);
$this->em->persist($pv);
$this->em->flush();
?>
Doctrine 從來沒有設置數據庫中的location_id(它始終爲NULL)。
我檢查的SQL查詢和他們還沒有被嘗試在被設置,所有我得到的是:
INSERT INTO View (field1, field2, created, updated) VALUES ('val1', 'val2', '2013-07-17T12:10:56+01:00', '2013-07-17T12:10:56+01:00')
沒有提到任何地方......奇怪的是我可以更新FIELD1和FIELD2罰款......和所有其他關係在我的應用程序的工作......我只是無法得到的觀點和地點工作...
編輯
我有確切一些代碼正在工作另一臺電腦。我不知道爲什麼它不工作,但我只是將文件移回並重新啓動我的電腦,現在它是...緩存問題,我猜?
查看http://stackoverflow.com/a/40526019/1794894瞭解更多詳情 – Rvanlaak