我正在尝试在 Doctrine 2 中构建一个查询,以查找Vacancy
与任何给定实体相关的所有VacancyWorkingHours
实体。
Vacancy
实体如下所示:
/**
* Vacancy
*
* @ORM\Table(name="vacancy")
* @ORM\Entity(repositoryClass="JaikDean\CareersBundle\Entity\VacancyRepository")
*/
class Vacancy
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var VacancyWorkingHours
*
* @ORM\ManyToOne(targetEntity="VacancyWorkingHours", inversedBy="vacancies")
* @ORM\JoinColumn(name="vacancy_working_hours_id", referencedColumnName="id")
**/
private $workingHours;
/* Other fields and methods are inconsequential */
}
我的查询目前如下所示,但由于 where 子句,没有返回任何结果。在此示例中,$workingHours
是一个Doctrine\Common\Collections\ArrayCollection
包含多个VacancyWorkingHours
实体的实例
$q = $this->createQueryBuilder('v')
->select('v')
->andWhere('v.workingHours IN (:workingHours)')
->setParameter('workingHours', $workingHours->toArray());
;