title: Symfony 2 join not working doctrine and MySQL
body: <p><strong>Note:</strong> this post was solved using <a href="https://stackoverflow.com/questions/23369285/symfony-2-join-not-working-doctrine">this</a> method, the problem was in one of my entities, so any thing I tried that would in normal conditions work, was bad functioning because of that. I do not know how to mark it now.</p>
  
  <p>I have the following repository entities: Vehicle, Job, FuelPurchase.</p>
  
  <p>For intance vahicle:</p>
  
  <pre><code>/**
   * @ORM\Entity
   * @ORM\Table(name="vehicle")
   * @ORM\Entity(repositoryClass="TeamERP\TransportBundle\Entity\VehicleRepository")
   */
  class Vehicle
  {
   /**
   * @ORM\Column(type="integer", name="id_vehicle")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  protected $idVehicle;
  /**
   * @ORM\Column(type="string", length=7, name="plate_number")
   */
  protected $plateNumber;
  
  /**
   * @ORM\Column(type="integer", name="distance_to_service")
   */ 
  protected $DistanceToServiceKm;
  /**
   * @ORM\Column(type="integer", name="last_service_odo")
   */ 
  protected $lastServiceODOKm; 
  /**
   * @ORM\Column(type="string", length=100, name="make")
   */
  protected $makeName;   
  /**
   * @ORM\Column(type="string", length=100, name="model")
   */
  protected $modelName;
  
  /**
  * @ORM\OneToMany(targetEntity="Job", mappedBy="vehicles")
  */
  protected $jobs;
  
  /**
  * @ORM\OneToMany(targetEntity="FuelPurchase", mappedBy="vehicles")
  */
  protected $fuelPurchaces;
  
  public function __construct()
  {
      $this-&gt;jobs = new ArrayCollection();
      $this-&gt;fuelPurchaces = new ArrayCollection();
  }
   ...  
  </code></pre>
  
  <p>and Fuel puchase is this:</p>
  
  <pre><code>/**
   * @ORM\Entity
   * @ORM\Table(name="fuel_purchace")
   * @ORM\Entity(repositoryClass="TeamERP\TransportBundle\Entity\FuelPurchaseRepository")
   */
  
  class FuelPurchase
  {
  /**
   * @ORM\Column(type="integer", name="id_fuel_purchace")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  protected $idFuelPurchace;
  /**
   * @ORM\Column(type="string", length=20, name="invoice_number")
   */
  protected $invoice; 
  /**
   * @ORM\Column(type="datetime", name="date_time")
   */
  protected $dateTime;
  /**
   * @ORM\Column(type="float", name="fuel_used", nullable=true) 
   */
  protected $fuelUsed;
  /**
   * @ORM\Column(type="float", name="fuel_price", nullable=true) 
   */
  protected $fuelPrice;
  /**
   * @ORM\Column(type="float", name="km_odo", nullable=true)
   */    
  protected $kmOdo;    
  /**
  * @ORM\ManyToOne(targetEntity="Vehicle", inversedBy="FuelPurchace")
  * @ORM\JoinColumn(name="id_vehicle", referencedColumnName="id_vehicle")
  */
  protected $vehicles;
  /**
  * @ORM\Column(type="string", length=250, name="refuling_remarks", nullable=true)
  */
  protected $remarks;
  /**
  * @ORM\Column(type="string", length=100, name="refuling_person", nullable=true)
  */
  protected $refueler;
  ...
  </code></pre>
  
  <p>Also the Job:</p>
  
  <pre><code>class Job
  {
  /**
   * @ORM\Column(type="integer", name="id_job")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  protected $idJob;
  /**
   * @ORM\Column(type="string", length=20, name="delivery_number")
   */
  protected $deliveryNo; 
  /**
   * @ORM\Column(type="datetime", name="date_time")
   */
  protected $dateTime;
  /**
   * @ORM\Column(type="string", length=200, name="destination")
   */
  protected $destination;      
  /**
   * @ORM\Column(type="float", name="km_odo_start", nullable=true)
   */    
  protected $kmOdoStart;   
  /**
   * @ORM\Column(type="float", name="km_odo_end", nullable=true)
   */    
  protected $kmOdoEnd;      
  
  /**
   * @ORM\Column(type="float", name="fuel_used", nullable=true) 
   */
  protected $fuelUsedLitre;
  /**
   * @ORM\Column(type="float", name="fuel_price", nullable=true) 
   */
  protected $fuelPrice;    
  /**
   * @ORM\Column(type="string", length=100, name="driver_name", nullable=true)
   */    
  protected $driverName;
  /**
   * @ORM\Column(type="string", length=250, name="crew_names", nullable=true)
   */    
  protected $crewNames;
  /**
   * @ORM\Column(type="string", length=7, name="triler_plate_number", nullable=true)
   */
  protected $trilerPlateNumber;
  /**
   * @ORM\Column(type="string", length=500, name="remarks", nullable=true)
   */
  protected $remarks;
  /**
   * @ORM\Column(type="string", length=500, name="return_load_plan", nullable=true)
   */
  protected $returnLoadPlan;
  /**
  * @ORM\ManyToOne(targetEntity="Vehicle", inversedBy="job")
  * @ORM\JoinColumn(name="id_vehicle", referencedColumnName="id_vehicle")
  */
  protected $Vehicles;    
  
  /**
  * @ORM\ManyToOne(targetEntity="JobStatus", inversedBy="job")
  * @ORM\JoinColumn(name="id_job_status", referencedColumnName="id_job_status")
  */
  protected $jobStatus;
  
  /**
  * @ORM\ManyToOne(targetEntity="JobType", inversedBy="job")
  * @ORM\JoinColumn(name="id_job_type", referencedColumnName="id_job_type")
  */
  protected $jobType;
  
  /* My functions Distance calculator*/
  public function getJobDistance ()
  {
      return $this-&gt;kmOdoEnd - $this-&gt;kmOdoStart;
  }
  ....
  </code></pre>
  
  <p>I am trying to make joins between the 3 of them to make a report, but I have started simple; a join between <code>Vehicle</code> and <code>FuelPurchase</code>, but I cant make it work. Check out my Vehicle repository: </p>
  
  <pre><code>class VehicleRepository extends EntityRepository
  {
  public function findByCriteria ($dateStart, $dateEnd)
  {
      $query = $this-&gt;createQueryBuilder();
              $query-&gt;select('v', 'f')
              -&gt;from('TeamERPTransportBundle:Vehicle', 'v')
              -&gt;innerJoin('TeamERPTransportBundle:FuelPurchase', 'f')
              -&gt;groupBy('v.plateNumber')
          -&gt;getQuery();
      return $query-&gt;getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
  }
  }
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <p><code>ContextErrorException: Warning: Missing argument 1 for Doctrine\ORM\EntityRepository::createQueryBuilder(), called in D:\Web\wamp\www\team\src\TeamERP\TransportBundle\Entity\VehicleRepository.php on line 17 and defined in D:\Web\wamp\www\team\vendor\doctrine\orm\lib\Doctrine\ORM\EntityRepository.php line 81</code></p>
  
  <p>Edition 1:
  I have also tryed this:</p>
  
  <pre><code>    $query = $this-&gt;createQueryBuilder('v');
              $query-&gt;select('v', 'f')
              -&gt;from('TeamERPTransportBundle:Vehicle', 'v')
              -&gt;innerJoin('TeamERPTransportBundle:FuelPurchase', 'f')
              -&gt;groupBy('v.plateNumber');
          $aux = $query-&gt;getQuery();
       $result = $aux-&gt;getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);   
       return $result;
  </code></pre>
  
  <p>And the error that I receive is this:</p>
  
  <p><code>[Syntax Error] line 0, col 106: Error: Expected Doctrine\ORM\Query\Lexer::T_WITH, got ','</code></p>
  
  <p>Ramoving <code>from</code>:</p>
  
  <pre><code>    $query = $this-&gt;createQueryBuilder('v');
              $query-&gt;select('v', 'f')
              -&gt;innerJoin('TeamERPTransportBundle:FuelPurchase', 'f')
              -&gt;groupBy('v.plateNumber');
          $aux = $query-&gt;getQuery();
       $result = $aux-&gt;getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);   
       return $result;
  </code></pre>
  
  <p>It gives this error:</p>
  
  <p>[Syntax Error] line 0, col 113: Error: Expected Literal, got 'BY'</p>
  
  <p>Edition 2:
  I managed to make a join with 2 tables work using the following code:</p>
  
  <pre><code>class VehicleRepository extends EntityRepository
  {
  public function findByCriteria ($dateStart = null, $dateEnd=null)
  {
      $query = $this-&gt;createQueryBuilder('v')
              -&gt;select('v.plateNumber','SUM(f.fuelUsed) as totalFuel', 'SUM(f.fuelUsed*f.fuelPrice) as totalFuelCost')
              -&gt;join('v.fuelPurchaces', 'f')
              //-&gt;join('v.jobs', 'j')
              -&gt;groupBy('v.plateNumber')
              -&gt;getQuery()-&gt;getResult();
      return $query;
  }
  }
  </code></pre>
  
  <p>Now what I cant do is to add a third table, if I remove the comment mark from the join for jobs, then I receive the following error:
  <code>ContextErrorException: Notice: Undefined index: vehicles in D:\Web\wamp\www\team\vendor\doctrine\orm\lib\Doctrine\ORM\Query\SqlWalker.php line 887</code></p>
  
  <p>Any Idea?
  Thank you any help will be appreciated.</p>