[英]Doctrine NOT IN query
我有:
$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) } }
我想用Doctrine編寫類似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')))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.