l3pp4rd/DoctrineExtensions — Issue #183: Tree object must have tree metadata at this point
Author: juriansluiman
Created: 2011-10-28 10:09:14+00:00
State: open

I have a similar issue as issue #117, where I get an exception "Tree object class Class\Name must have tree metadata at this point". As far as I know, I register the namespace correctly:

```php
use Doctrine\Common\Annotation\AnnotationRegistry;

AnnotationRegistry::registerAutloadNamespaces(array('Gedmo' => '/path/to/Gedmo/lib'));
```

I set up the listener:

```php
use Doctrine\Common\EventManager,
Gedmo\Tree\TreeListener;

$evm = new EventManager;
$tree = new TreeListener;
$evm->addEventSubscriber($tree);
```
The eventmanager is passed to the connection, the connection to the entity manager.

My entity:

```php
namespace My\Foo\Model;

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

/**
* @Gedmo\Tree(type="nested")
* @ORM\Table(name="pages")
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
*/
class Page
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;

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

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

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

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

/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="My\Foo\Model\Page", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $parent;

/**
* @ORM\OneToMany(targetEntity="My\Foo\Model\Page", mappedBy="parent")
* @ORM\OrderBy({"lft" = "ASC"})
*/
protected $children;
}
```

What I do to trigger the exception:

```php
// $em instanceof EntityManager
$pages = $em->getRepository('My\Foo\Model\Page')->getRootNodes();
```

What's wrong and how can I fix this?