symfony - Symfony2 form choice field -
i have product
, category
entity.
category
entity adjacency list/materialized-path model.
product
has relation category
has relation product
in producttype
class selectmenu categories @ specific level grouped parent name.
$builder->add('category', 'entity', array( 'label' => 'category', 'class' => 'test\adminbundle\entity\category', 'property' => 'name', 'group_by' => 'parentname', 'query_builder' => function(\doctrine\orm\entityrepository $er) { $qb = $er->createquerybuilder('c'); return $qb->where($qb->expr()->like('c.path', ':path')) ->orderby('c.path', 'asc') ->setparameter('path', '%/%/%'); }, ));
category
got getparentname
method:
public function getparentname() { if (null === $this->getparent()) { return null; } return $this->getparent()->getname(); }
it works expected query executed every parent (a lot). if make join parent parent selectable in selectmenu don't want.
how limit queries?
or filter joined result?
i not fetchjoining... adding select querybuilder made work:
$qb = $er->createquerybuilder('c'); return $qb->select('c, p') ->leftjoin('c.parent', 'p') ->where($qb->expr()->like('c.path', ':path')) ->orderby('c.path', 'asc') ->setparameter('path', '%/%/%');
Comments
Post a Comment