我有:
$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第一个查询,但查询:
$rooms = $qb->select('ro')
->from(''Model'Room', 'ro')
->where($qb->expr()->notIn('ro.id', $reservations))
->getQuery()
->getResult();
给我错误:
错误:无效的参数编号:绑定变量的数量与令牌的数量不匹配
请帮帮我。
更改
->where($qb->expr()->notIn('ro.id', $reservations))
至
->where($qb->expr()->notIn('ro.id', array_column($reservations, 'id')))