Entity framework Symfony2筛选表单中的集合

Entity framework Symfony2筛选表单中的集合,entity-framework,symfony,doctrine,symfony-forms,Entity Framework,Symfony,Doctrine,Symfony Forms,我们有一个用户实体,它与其他实体有关系(OneToMany)。为用户实体生成FormType时。我们将关联实体作为集合 $builder->add('sso_users_organization', "collection", array('type'=>new UsersOrganizationType(),'allow_add' => true) ); 我们只想显示根据状态“活动”进行过滤的关联实体 我们尝试过用下面的方法过滤 $organization

我们有一个用户实体,它与其他实体有关系(OneToMany)。为用户实体生成FormType时。我们将关联实体作为集合

         $builder->add('sso_users_organization', "collection", array('type'=>new UsersOrganizationType(),'allow_add' => true) );
我们只想显示根据状态“活动”进行过滤的关联实体

我们尝试过用下面的方法过滤

$organizations = $userEntity->getSsoUsersOrganization();
foreach($organizations as $key=>$org){
    if($org->getStatus() == 0){
       unset($organizations[$key]);
    }
}
但是,当我们将详细信息保存回来时,其他状态为“非活动”的记录将被删除

谁能帮我一下吗


谢谢

试试这样的东西$er是“类”指定类型的实体存储库。在本例中,用户或组织类型存储库

$builder->add('sso_users_organization', "entity", array(
    "class" => "Acme\AppBundle\UsersOrganizationType",
    "query_builder" => function(EntityRepository $er){
         return $er->createQueryBuilder('uot')
             ->where('uot.active = true');
     }
 );

此字段不是select元素,包含作为集合的子表单,对于集合类型,我们不能使用query\u builder.My bad,不能以这种方式理解它。