[英]Bidirectional One-To-One Relationships in Flow
是否可以在流中具有一對一關系而不必兩次設置屬性 ?
我有兩個表以一對一關系連接,但是其中只有一個表應包含此關系的額外列。
教義明確支持這種行為: http : //doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html#one-to-one-bidirectional
componenttape列應附帶的類:
/**
* @Flow\Entity
*/
class Component{
/**
* @var \Some\Package\Domain\Model\Component\Tape
* @ORM\OneToOne(cascade={"all"}, inversedBy="component")
*/
protected $componentTape;
…
}
無需額外的列就應該能夠找到連接的類:
/**
* @Flow\Entity
*/
class Tape{
/**
* @var \ Some\Package\Domain\Model\Component
* @ORM\OneToOne(mappedBy="componentTape")
*/
protected $component;
}
理論更新將為兩個模型創建額外的列。
這是我目前的工作環境:
class Component{
..
/**
* @param \Some\Package\Domain\Model\Component\Tape $componentTape
* @return void
*/
public function setComponentTape($componentTape) {
$this->componentTape = $componentTape;
$this->componentTape->setComponent($this);
}
無論如何,都必須采取變通方法以在請求期間始終保持正確的關系。 但是第二個DB列不是必需的。 您是否檢查過教義是否真正滿足了要求? 也許/也許只是創建的遷移是錯誤的,並且Tape
的component
列可以省略。
您的解決方法Stil對您有用嗎? 就我而言,我必須自行更新存儲庫上的ComponentTape模型:
class Component {
/**
* @param \Some\Package\Domain\Model\Component\Tape $componentTape
* @return void
*/
public function setComponentTape($componentTape) {
$this->componentTape = $componentTape;
$this->componentTape->setComponent($this);
$this->componentTapeRepository->update($this->componentTape);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.