Question: I am using sonataAdminBundle and symfony2

I made this script.
it filter the search box candidates.

but this query\_builder is ignored.

Are there any other points to check ?

```
public function configureDatagridFilters(DatagridMapper $datagridMapper)
{

    $datagridMapper
        ->add('user',null,
            array(
                'query_builder' =>
                function (\Doctrine\ORM\EntityRepository $rep) {
                     return $rep->
                     createQueryBuilder('s')
                     ->where('s.id','1');
             })       

```

---

adding...

I am using this script for new entry,it works

```
    $formMapper
        ->with('General')
            ->add('teacher',
                null,
                array(
                    'query_builder' =>
                     function (\Doctrine\ORM\EntityRepository $rep) {
                     return $rep->
                    createQueryBuilder('s')
                    ->join('s.groups', 'g') // Assuming the association on your user entity is 'groups'
                    ->where('g.name = :group')->setParameter('group','TeacherGroup');
                    })

            ) 

```

but for datagridMapper ,it doesnt work.

```
    $datagridMapper
        ->add('teacher',null,
            array(
               'query_builder' =>
                function (\Doctrine\ORM\EntityRepository $rep) {
                return $rep->
                createQueryBuilder('s')
                ->join('s.groups', 'g') // Assuming the association on your user entity is 'groups'
                ->where('g.name = :group')
                ->setParameter('group','TeacherGroup');
             }))

```

Answer: 
I have achieved this in the following way

```
 $datagridMapper
    ->add('user',null,
        array(
            'field_type' => 'entity',
            'field_options => array(
              'query_builder' => function (\Doctrine\ORM\EntityRepository $rep) {
                 return $rep->
                 createQueryBuilder('s')
                 ->where('s.id','1');
              }
            )
         });       

```
Check out the documentation about this. You have the wrong syntax.
<http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/filter_field_definition.html#callback>