我得到了一个错误,即 [Semantical Error] line 0, col 57 near 'room FROM AppBundle:bookings': Error: Invalid PathExpression. Must be a StateFieldPathExpression.
我在AppBundle中有两个实体,它们是房间和预订。执行查询后,我以前会提到错误。在这里我的查询:
$query = $em->createQuery(
'SELECT r ' .
'FROM AppBundle:Room r ' .
'WHERE r NOT IN ( ' .
'SELECT b.room ' .
'FROM AppBundle:Bookings b ' .
'WHERE NOT ( ' .
'b.check_out < :check_in ' .
'OR ' .
'b.check_in > :check_out ' .
')' .
') ' .
'ORDER BY r.id'
)
->setParameter('check_in', $request->query->get('check-in'))
->setParameter('check_out', $request->query->get('check-out'));
我认为问题是关于WHERE NOT
的。尝试此查询:
$query = $em->createQuery(
'SELECT r ' .
'FROM AppBundle:Room r ' .
'WHERE r NOT IN ( ' .
'SELECT b.room ' .
'FROM AppBundle:Bookings b ' .
'WHERE ' .
'b.check_out < :check_in ' .
'OR ' .
'b.check_in > :check_out ' .
') ' .
'ORDER BY r.id'
)
->setParameter('check_in', $request->query->get('check-in'))
->setParameter('check_out', $request->query->get('check-out'));