[Symfony2] Node is not related to this repository
Bonjour,
J'utilise l'extension tree de Doctrine et j'ai un message d'erreur que je n'arrive pas à résoudre.
Mon repository hérite de NestedTreeRepository et je n'arrive pas à utiliser les fonctions de cette interface.
J'ai mis à null le premier argument de getChildrenQuery pour faire simple.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| use Gedmo\Tree\Entity\Repository\NestedTreeRepository as NestedTreeRepository;
use Gedmo\Tool\Wrapper\EntityWrapper;
/**
* ReferentielRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ReferentielRepository extends NestedTreeRepository
{
public function myFetchFindOneByCode($code, $df)
{
$qb = $this->getChildrenQuery(
null,
false,
null,
'ASC',
false
);
$results = $qb->getResult();
return $results;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| $currentUser = $this->get('security.context')->getToken()->getUser();
$referentiel = $em->getRepository('ContrastReferentielBundle:Organisation')
->myFetchFindOneByCode("BU1", $currentUser->getDomaineFonctionnels()->first());
$htmlTree = "";
$htmlTree .= $repo->childrenHierarchy(
$referentiel,
false,
$options,
true
); |
Le message d'erreur retourné est:
Citation:
Node is not related to this repository
Quand je regarde la class NestedTreeRepository, j'observe ceci:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public function childrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false)
{
$meta = $this->getClassMetadata();
$config = $this->listener->getConfiguration($this->_em, $meta->name);
$qb = $this->getQueryBuilder();
$qb->select('node')
->from($config['useObjectClass'], 'node')
;
if ($node !== null) {
if ($node instanceof $meta->name) {
...
} else {
throw new \InvalidArgumentException("Node is not related to this repository");
} |