I'm using Doctrine, and now I have the following problem.
I'm doing a system registry, where it can have multiple "children" and their "children" can also have "children", and so on.
How will I achieve this self-relationship with the doctrine?
I have already mapped the Menu class to the annotations , but I could not figure out how to do this mapping in the query, so when I perform the search the menu object will already be filled with all the items correctly.
Below is the mapping I made in the Menu class:
/**
* @ORM\Entity
* @ORM\Table(name="tb_Menu")
*/
class Menu
{
/**
* @ORM\Id
* @ORM\GeneratedValue("SEQUENCE")
* @ORM\Column(type="integer", nullable=false)
* @ORM\SequenceGenerator(sequenceName="sq_Menu")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Menu", inversedBy="menuFilho")
* @ORM\JoinColumn(name="idMenuPai", referencedColumnName="id")
*/
private $menuPai;
/**
* @ORM\OneToMany(targetEntity="Menu", mappedBy="menuPai")
*/
private $menuFilho;
/**
* @ORM\Column(type="string", length=30, unique=true, nullable=false)
*/
private $titulo;
/**
* @ORM\Column(type="string", length=80)
*/
private $descricao;
/*
* Construtor
*/
public function __construct() {
$this->menuFilho = new ArrayCollection();
}
}