我有以下实体:
车辆-参考表,用于存储下一个实体之间的关联 使 模型 子模型
现在,根据车辆的“年份”和“品牌”,我试图返回可用的子模型,或者如果给定的车辆不可用,则不返回任何子模型。在我的示例中,$ make ='Mazda'和$ year ='2016'
由于某种原因,以下查询在不应该返回任何子模型时,返回属于Kia:D的子模型。我在做什么错了?
$qb = $this->createQueryBuilder('submodel');
$qb->select('submodel', 'vehicles')
->join('submodel.vehicles', 'vehicles')
->join('vehicles.make', 'make')
->Where('make.makeName = :makeName')->setParameter('makeName', $makeName)
->AndWhere('vehicles.year = :year')->setParameter('year', $year);
$results = $qb->getQuery()->getResult();
车辆实体:
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="create_time", type="datetime")
*/
protected $createTime;
/**
* @var \DateTime
*
* @ORM\Column(name="update_time", type="datetime")
*/
protected $updateTime;
/**
* @var integer
*
* @ORM\Column(name="year", type="integer", length=4)
*/
private $year;
/**
* @ORM\ManyToOne(targetEntity="PhilipsMake", inversedBy="vehicles")
* @ORM\JoinColumn(name="make_id", referencedColumnName="id")
*/
private $make;
/**
* @ORM\ManyToOne(targetEntity="PhilipsModel", inversedBy="vehicles")
* @ORM\JoinColumn(name="model_id", referencedColumnName="id")
*/
private $model;
/**
* @ORM\ManyToOne(targetEntity="PhilipsSubmodel", inversedBy="vehicles")
* @ORM\JoinColumn(name="submodel_id", referencedColumnName="id")
*/
private $submodel;
/**
* @ORM\ManyToOne(targetEntity="PhilipsBodytype")
* @ORM\JoinColumn(name="bodytype_id", referencedColumnName="id")
*/
private $bodytype;
/**
* @ORM\ManyToOne(targetEntity="PhilipsNumberOfDoors")
* @ORM\JoinColumn(name="number_of_doors_id", referencedColumnName="id")
*/
private $numberOfDoors;
/**
* @ORM\ManyToOne(targetEntity="PhilipsQualifier")
* @ORM\JoinColumn(name="qualifier", referencedColumnName="id")
*/
private $qualifier;
/**
* @ORM\ManyToMany(targetEntity="PhilipsLight", mappedBy="vehicles")
*/
private $lights;
子模型实体:
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="create_time", type="datetime")
*/
protected $createTime;
/**
* @var \DateTime
*
* @ORM\Column(name="update_time", type="datetime")
*/
protected $updateTime;
/**
* @var string
*
* @ORM\Column(name="submodel_name", type="string", length=100, nullable=true, unique=true)
*/
private $submodelName;
/**
* @ORM\OneToMany(targetEntity="PhilipsVehicle", mappedBy="make", orphanRemoval=true, cascade={"persist"})
*/
protected $vehicles;