1

I want to create a FAQ System, where the admin is able to create another FAQ in the FAQ a SubFAQ in the FAQ and so on..

I know that I need to self-reference, but how could I solve this?

My Entity FAQ.php looks like this:

 /**
  * @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();
 }

What I don't understand is the inversedBy and how to use all this.

Thank you.

ArK
  • 20,698
  • 67
  • 109
  • 136
yz55
  • 27
  • 7
  • http://stackoverflow.com/questions/12493865/what-is-the-difference-between-inversedby-and-mappedby#12495834 may help. – Gerard Roche Aug 20 '16 at 16:57
  • Also http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/reference/association-mapping.html#association-mapping . – Gerard Roche Aug 20 '16 at 16:58

1 Answers1

1

You'd have to add some methods to add SubFAQs and return all SubFAQs.

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

    return $this;
}

/**
 * @return ArrayCollection
 */
public function getSubFAQs()
{
    return $this->children;
}
keyboardSmasher
  • 2,661
  • 18
  • 20