【发布时间】:2016-04-06 17:52:53
【问题描述】:
我有:
$from = new \DateTime($from);
$to = new \DateTime($to);
$qb = $this->em->createQueryBuilder();
$reservations = $qb
->select('rr.id')
->from('\Model\Reservation', 're')
->join('re.rooms', 'rr')
->where('(re.fromDate < ?1 AND re.toDate <= ?2 AND re.toDate > ?1) OR (re.fromDate >= ?1 AND re.fromDate < ?2)')
->setParameters(array(1 => $from, 2 => $to))
->getQuery()
->getResult();
我有结果:
array(2) { [0]=> array(1) { ["id"]=> int(2) } [1]=> array(1) { ["id"]=> int(2) } }
我想用 SELECT ... WHERE NOT IN 第一个查询之类的 Doctrine 编写查询,但是查询:
$rooms = $qb->select('ro')
->from('\Model\Room', 'ro')
->where($qb->expr()->notIn('ro.id', $reservations))
->getQuery()
->getResult();
给我错误:
错误:参数号无效:绑定变量的数量与标记的数量不匹配
请帮帮我。
【问题讨论】:
-
$reservations看起来像什么? -
array(2) { [0]=> array(1) { ["id"]=> int(2) } [1]=> array(1) { ["id"] => int(2) } }.
标签: php sql doctrine-orm