原则 2 WHERE IN 条款使用实体集合
2022-08-30 18:20:26
我试图在教义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());
;