2016-08-20 20 views
1

私は管理者がその上のFAQでFAQにSubFAQを別のFAQを作成し、することができますよくある質問システムを作成したい。..教義自己参照協会マッピング(symfonyの)

私が知っているI自己参照が必要ですが、どうすればこの問題を解決できますか?

私のエンティティ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であり、このすべてを使用する方法。

ありがとうございます。

+0

http://stackoverflow.com/questions/12493865/what-is-the-difference-between-inversedby-and-mappedby#12495834が役立ちます。 –

+0

http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/reference/association-mapping.html#association-mapping –

答えて

1

SubFAQを追加してすべてのSubFAQを返す方法をいくつか追加する必要があります。

/** 
* @param Faq $child 
* 
* @return Faq 
*/ 
public function addSubFAQ($child) 
{ 
    $this->children[] = $child; 

    return $this; 
} 

/** 
* @return ArrayCollection 
*/ 
public function getSubFAQs() 
{ 
    return $this->children; 
}