Symfony 2加入了不起作用的学说

时间:2014-04-29 15:42:18

标签: php symfony doctrine-orm dql

我有2个具有OnrtoMany关系的实体,具有许多工作的Vehicle。我试图在VehicleRepository中创建这个函数:

public function findByJobXVehicle($dateStart = null, $dateEnd=null){
    $query = $this->createQueryBuilder('v')
                ->select('v.plateNumber','SUM(j.kmOdoEnd - j.kmOdoStart) as dist')
                ->join('v.jobs', 'j')
                ->groupBy('v.plateNumber');
             $q = $query->getQuery()->getResult();
             //get_class($q[0]);
    return $q;
}

目标载体是:

<?php
namespace TeamERP\TransportBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
 * @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->jobs = new ArrayCollection();
    $this->fuelPurchaces = new ArrayCollection();
}

然后约伯有以下内容:

<?php
namespace TeamERP\TransportBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
/**
 * @ORM\Entity
 * @ORM\Table(name="job")
 * @ORM\Entity(repositoryClass="TeamERP\TransportBundle\Entity\JobRepository")
 */
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->kmOdoEnd - $this->kmOdoStart;
}
/* My functions job cost calculator*/
public function getJobFuelCost ()
{
    return $this->fuelPrice * $this->fuelUsedLitre;
}
/*My functions cost per Km */
public function getFuelCosdPerKm ()
{
    if ($this->getJobFuelCost() > 0)            
        return round($this->getJobDistance()/$this->getJobFuelCost(),3);        
    return 0;
}

我收到此错误: ContextErrorException: Notice: Undefined index: vehicles in D:\Web\wamp\www\team\vendor\doctrine\orm\lib\Doctrine\ORM\Query\SqlWalker.php line 887

我不知道在哪里看!有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

javad是正确的$ Vehicles mapping指向不存在的变量或数组集合。在您与这些相同实体的其他相关问题上,您发布了Fuel Purchase实体,该实体在inversedBy映射中可能有一个奇怪的类似错误。