2012-08-11 5 views
5

でなければならない私はSymfony2のクエリビルダに新しいです、ここで私が何をすべきかです:エラー:PathExpressionが無効です。 StateFieldPathExpression

$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; 
      } 
     ));  

私は(リレーショナルフィールドで、FK)containerTypeで私のエンティティを注文したい除いそれは正常に動作します。

私はこの行を追加する場合:無効PathExpression:

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

を私はエラーを取得。 StateFieldPathExpressionでなければなりません。

これは何ですか?私のwhere句ではrelationフィールドcontainerTypeを使用できますが、私のソート句では使用できません。あるいは私は何か他のものを逃していますかあなたが現在との関係で、この実体ので、ソート句でcontainerTypeを使用することはできません

答えて

6
'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はエンティティのIDを表します)。 エンティティに参加し、そのフィールドで手動でソートする必要があります。

+0

はい、このfkで並べ替えることはこの場合行いますが、明らかにできません。ちょうどそれが私がwhere節でjoinを使わずに使うことができるのは奇妙だと分かっていました。しかし、ありがとう、それを試してみましょう。 –

関連する問題