Error: Invalid PathExpression. Must be a StateFieldPathExpression

Viewed 13873

I am new to the Symfony2 query builder, here is 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 fine except I want to order my entities by containerType (which is a relational field, FK).

When I add this line:

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

I get Error: Invalid PathExpression. Must be a StateFieldPathExpression.

So what is this - I can use the relation field containerType in my where clause but not in my sort clause? Or am I missing something else?

1 Answers
Related