title: Create sql query in sonata admin
body: <p>I use sonata admin in my project. i created two admin classes exam and student. i want to create an action in exam class that shows all students that should pass the exam after creating a new exam, this is the sql query that i want:</p>
  
  <pre><code>"Select * from student,exam where student.codeAdministration=exam.codeAdministration"
  </code></pre>
  
  <p>examAdmin.php:</p>
  
  <pre><code>&lt;?php
  
  namespace Exam\ExamBundle\Admin;
  
  use Sonata\AdminBundle\Admin\Admin;
  use Sonata\AdminBundle\Datagrid\ListMapper;
  use Sonata\AdminBundle\Datagrid\DatagridMapper;
  use Sonata\AdminBundle\Validator\ErrorElement;
  use Sonata\AdminBundle\Form\FormMapper;
  use Sonata\AdminBundle\Show\ShowMapper;
  
  class ExamAdmin extends Admin
  {
       ////
       protected function configureFormFields(FormMapper $formMapper)
       {
          //////
       }
       protected function configureDatagridFilters(DatagridMapper $datagridMapper)
       {
          ////
       }
       protected function configureListFields(ListMapper $listMapper)
       {
          /////
       }
  
       protected function configureShowField(ShowMapper $showMapper)
       {
           //////
       }
  
  }
  </code></pre>
  
  <p>i tried this query without putting the condition of WHERE but it does not work:</p>
  
  <pre><code>protected function configureListFields(ListMapper $listMapper)
  {
      $query = $this-&gt;modelManager-&gt;getEntityManager()-&gt;createQuery('SELECT s FROM Exam\ExamBundle\Entity\student s');
  
      $listMapper
  
          -&gt;add('student', 'sonata_type_model', array('required' =&gt; true, 'query' =&gt; $query))
  }
  </code></pre>
  
  <p>How can i create this action with this query??</p>
  
  <p>exam.php:</p>
  
  <pre><code>&lt;?php
  
  namespace Exam\ExamBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  class Exam
  {
      /**
       * @var integer
       */
      private $idExam
  
      ////////
  
      /**
       * @var \Examens\ExamensBundle\Entity\Administration
       */
      private $codeAdministration;
  
      //////
      public function getIdExam()
      {
          return $this-&gt;idExam;
      }
  
      ///////
      public function setCodeAdministration(\Exam\ExamBundle\Entity\Administration $codeAdministration = null)
      {
          $this-&gt;codeAdministration = $codeAdministration;
  
          return $this;
      }
  
      /**
       * Get codeAdministration
       *
       * @return \Exam\ExamBundle\Entity\Administration 
       */
      public function getCodeAdministration()
      {
          return $this-&gt;codeAdministration;
      }
      ///////
  }
  </code></pre>