title: Select query with doctrine
body: <p>I was trying to create a select query with doctrine but it didn't work.
  I have three tables, Product(ID, Name), Client(ID, Name), Orders(product, client). 
  I need to select and show all the orders made by a client, and also the product name.
  How can I make this particular query using doctrine?
  Sorry if it's a banal question...</p>
  
  <p>Produt:</p>
  
  <pre><code>&lt;?php
  namespace Example\Bundle\CrudBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Product
   */
  class Product
  {
  /**
   * @var string
   */
  private $name;
  
  /**
   * @var string
   */
  private $prize;
  
  /**
   * @var integer
   */
  private $id;
  
  
  /**
   * Set name
   *
   * @param string $name
   * @return Product
   */
  public function setName($name)
  {
      $this-&gt;name = $name;
  
      return $this;
  }
  
  /**
   * Get name
   *
   * @return string 
   */
  public function getName()
  {
      return $this-&gt;name;
  }
  
  /**
   * Set prize
   *
   * @param string $prize
   * @return Product
   */
  public function setPrize($prize)
  {
      $this-&gt;prize= $prize;
  
      return $this;
  }
  
  /**
   * Get prize
   *
   * @return string 
   */
  public function getprize()
  {
      return $this-&gt;prize;
  }
  
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>&lt;?php
  namespace Example\Bundle\CrudBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
  * Client
  */
  class Client
  {
  /**
   * @var string
   */
  private $name;
  
  /**
   * @var string
   */
  private $age;
  
  /**
   * @var integer
   */
  private $id;
  
  
  /**
   * Set name
   *
   * @param string $name
   * @return Client
   */
  public function setName($name)
  {
      $this-&gt;name = $name;
  
      return $this;
  }
  
  /**
   * Get name
   *
   * @return string 
   */
  public function getName()
  {
      return $this-&gt;name;
  }
  
  /**
   * Set age
   *
   * @param string $age
   * @return Client
   */
  public function setAge($age)
  {
      $this-&gt;age = $age;
  
      return $this;
  }
  
  /**
   * Get age
   *
   * @return string 
   */
  public function getAge()
  {
      return $this-&gt;age;
  }
  
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Orders:</p>
  
  <pre><code>&lt;?php
  namespace Example\Bundle\CrudBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Orders
   */
  class Orders
  {
  /**
   * @var integer
   */
  private $idProduct;
  
  /**
   * @var integer
   */
  private $idIngrediente;
  
  
  /**
   * Set idProduct
   *
   * @param integer $idProduct
   * @return Orders
   */
  public function setIdProduct($idProduct)
  {
      $this-&gt;idProduct = $idProduct;
  
      return $this;
  }
  
  /**
   * Get idProduct
   *
   * @return integer 
   */
  public function getIdProduct()
  {
      return $this-&gt;idProduct;
  }
  
  /**
   * Set idClient
   *
   * @param integer $idClient
   * @return Orders
   */
  public function setIdClient($idIngrediente)
  {
      $this-&gt;idClient= $idClient;
  
      return $this;
  }
  
  /**
   * Get idClient
   *
   * @return integer 
   */
  public function getIdClient()
  {
      return $this-&gt;idClient;
  }
  }
  </code></pre>
  
  <p>This is how I was trying to make the query, by first checking if the product is in the table and then selecting the fields I need from both the Orders and the Product tables.</p>
  
  <pre><code>class ProductRepository extends EntityRepository
  {
      public function findAllOrderedByName()
      {
          return $this-&gt;getEntityManager()
              -&gt;createQuery(
                  'SELECT * FROM ExampleCrudBundle:Product p ORDER BY p.name ASC'
              )
              -&gt;getResult();
      }
  }
  
  
  public function findOneByIdJoinedToCategory($id)
  {
      $query = $this-&gt;getEntityManager()
          -&gt;createQuery('
              SELECT p, c FROM ExampleCrudBundle:Product p
              JOIN p.category c
              WHERE p.id = :id'
          )-&gt;setParameter('id', $id);
  
      try {
          return $query-&gt;getSingleResult();
      } catch (\Doctrine\ORM\NoResultException $e) {
          return null;
      }
  }
  </code></pre>