I have tried following the instructions on Doctrines manuals: http://docs.doctrine-project.org/en/latest/reference/association-mapping.html#many-to-many-self-referencing
I'm trying to setup a pages entity, which has many subPages and I would also like to be able to access a pages parentPage.
Following the instructions above I am told by symfony2 that I need to setup a "use" due to a semantic error.
Could anybody instruct me on what to do to allow me to do this as I am quite stuck.
Sample code is:
namespace Pages\Bundle\PageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Page
*
* @ORM\Table(name="Page")
* @ORM\Entity(repositoryClass="Pages\Bundle\PageBundle\Entity\PageRepository")
*/
class Page
{
/**
* Constructor
*/
public function __construct()
{
$this->subPages = new \Doctrine\Common\Collections\ArrayCollection();
$this->parentPages = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @ManyToMany(targetEntity="Page", mappedBy="subPages")
**/
private $parentPages;
/**
* @ManyToMany(targetEntity="Page", inversedBy="parentPages")
* @JoinTable(name="sub_pages",
* joinColumns={@JoinColumn(name="parent_page_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="sub_page_id", referencedColumnName="id")}
* )
**/
private $subPages;
... (other variables follow but are content / metas)
Error response when running is:
[Semantical Error] The annotation "@ManyToMany" in property
Pages\Bundle\PageBundle\Entity\Page::$parentPages was never imported. Did you maybe forget to add a "use" statement for this annotation?