Symfony2 Doctrine,设置一个具有多对多自引用关系的页面

jag*_*get 5 orm doctrine many-to-many self-reference symfony

我试过按照Doctrines手册上的说明进行操作:http: //docs.doctrine-project.org/en/latest/reference/association-mapping.html#many-to-many-self-referencing

我正在尝试设置一个页面实体,它有许多子页面,我也希望能够访问页面parentPage.

按照上面的说明,symfony2告诉我,由于语义错误,我需要设置"使用".

任何人都可以告诉我该做什么让我这样做,因为我很困难.

示例代码是:

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;
Run Code Online (Sandbox Code Playgroud)

...(其他变量如下,但是内容/元数据)

运行时的错误响应是:

[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?
Run Code Online (Sandbox Code Playgroud)

Lor*_*con 16

尝试使用@ORM\ManyToMany而不仅仅是@ManyToMany

(还有@ORM\JoinTable)