在我的实体中,我有一个用户数组集合。
/**
* @ORM\ManyToMany(targetEntity="\UserBundle\Entity\User", mappedBy="acr_groups")
*/
protected $users;
public function __construct() {
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
}
在我的FormType中,我想要过滤掉当前用户是成员的那些组:
$builder
->add('acr_group', EntityType::class, array(
'label' => 'ATS',
'class' => 'HazardlogBundle:ACRGroup',
'query_builder' => function (EntityRepository $er) use ($user) { // 3. use the user variable in the querybilder
$qb = $er->createQueryBuilder('g');
$qb->where(':user IN (g.users)');
$qb->setParameters( array('user' => $user) );
$qb->orderBy('g.name', 'ASC');
return $qb;
},
'choice_label' => 'name'
))
我的问题显然在这一行:
$qb->where(':user IN (g.users)');
如何将我的用户集合作为IN()的参数使用?
in
表达式,像这样:$qb->where($qb->expr()->in('g.users', $user));
- Stephan Yamilov