1

I want to use the tree feature of DoctrineExtensions for my Symfony2 application.

But I get this error :

Tree object class: MyBundle\Entity\Category must have tree metadata at this point.

Symfony : v2.5.3

Doctrine Common : v2.4.2

DoctrineExtensions : Master

<?php

namespace MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * Category
 * @Gedmo\Tree(type="nested")
 * @ORM\Table(name="category", uniqueConstraints={@ORM\UniqueConstraint(name="id", columns={"id"})})
 * use repository for handy tree functions
 * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
 */
class Category
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

     /**
     * @Gedmo\TreeLeft
     * @ORM\Column(name="lft", type="integer")
     */
    private $lft;

    /**
     * @Gedmo\TreeLevel
     * @ORM\Column(name="lvl", type="integer")
     */
    private $lvl;

     /**
     * @Gedmo\TreeRight
     * @ORM\Column(name="rgt", type="integer")
     */
    private $rght;

    /**
     * @Gedmo\TreeRoot
     * @ORM\Column(name="root", type="integer", nullable=true)
     */
    private $root;

     /**
     * @Gedmo\TreeParent
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
     * @ORM\JoinColumn(name="parentId", referencedColumnName="id", onDelete="CASCADE")
     */
    private $parentid;

    /**
     * @ORM\OneToMany(targetEntity="Category", mappedBy="parentid")
     * @ORM\OrderBy({"lft" = "ASC"})
     */
    private $children;

I followed this document to Install Gedmo Doctrine2 extensions in Symfony2, but it seems something is wrong.

Milad Safaei
  • 492
  • 1
  • 5
  • 16
  • Hi, did you find the solution to this question? I'm encountering similar issue. Sadly mine is not constant, it happens after some time (like 1-3 days). then we have to clear the cache (restart apache), and everything works well for some time. – PolishDeveloper Jul 09 '15 at 12:19
  • Hi, unfortunately no ! – Milad Safaei Jul 11 '15 at 18:35

2 Answers2

1

Maybe this will help someone. In my case I restarted the webserver and fpm and this error was gone.

TheGhostex
  • 21
  • 6
0

I see that this question has been asked 3y ago, but anyways. I guess the problem is that u must initilize the doctrine tree, in CategoryRepository constructor, so u need this snippet of code in ur repo :

use NestedTreeRepositoryTrait;
$this->initializeTreeRepository($em, $class);