Error: Invalid path output. Must be a StateFieldPathExpression expression

I'm new to Symfony2's query builder, here's what I do:

    $builder
        ->add('access', 'entity', array(
            'label' => 'Behörigheter',
            'multiple' => true,   // Multiple selection allowed
            'expanded' => true,   // Render as checkboxes
            'property' => 'name', // Assuming that the entity has a "name" property
            'class'    => 'BizTV\ContainerManagementBundle\Entity\Container',
            'query_builder' => function(\Doctrine\ORM\EntityRepository $er) use ($company) {
                $qb = $er->createQueryBuilder('a');
                $qb->where('a.containerType IN (:containers)', 'a.company = :company');
                $qb->setParameters( array('containers' => array(1,2,3,4), 'company' => $company) );

                return $qb;
            }
        ));     

It works great, except that I want to order my objects using containerType (which is the FK relational field).

When I add this line:

$qb->orderBy('a.containerType', 'ASC');

I get Error: Invalid PathExpression. There must be a StateFieldPathExpression expression.

So what is it - can I use the containerType relation field in my where argument, but not in my sorting question? Or am I missing something else?

+5
source share
1 answer
'query_builder' => function(\Doctrine\ORM\EntityRepository $er) use ($company) {
      $qb = $er->createQueryBuilder('a');
      $qb->innerJoin('a.containerType', 'ct');
      $qb->where('a.containerType IN (:containers)', 'a.company = :company');
      $qb->orderBy('ct.id', 'ASC'); // Or the field you want from containerType
      $qb->setParameters( array('containers' => array(1,2,3,4), 'company' => $company));

      return $qb;
}

containerType sort, ! ( containerType !). , !

+6

All Articles