I'm new to Symfony2's query builder, here's what I do:
$builder
->add('access', 'entity', array(
'label' => 'Behörigheter',
'multiple' => true,
'expanded' => true,
'property' => 'name',
'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?
source
share