1
我想創建一個FAQ系統,其中系統管理員能在FAQ中的常見問題等,以創建另一個常見問題一SubFAQ ..學說自引用關聯映射(Symfony的)
我知道我需要自我參考,但我怎麼能解決這個問題?
我的實體FAQ.php看起來是這樣的:
/**
* @OneToMany(targetEntity="Faq", mappedBy="parent")
*/
private $children;
/**
* @ManyToOne(targetEntity="Faq", inversedBy="children")
* @JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parent;
public function __construct() {
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
}
什麼我不明白的是inversedBy以及如何使用這一切。
謝謝。
http://stackoverflow.com/questions/12493865/what-is-the-difference-between-inversedby-and-mappedby#12495834可能會有幫助。 –
也http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/reference/association-mapping.html#association-mapping。 –