无效的PathExpression。必须是StateFieldPathExpression

时间:2017-12-18 16:22:21

标签: mysql symfony doctrine-orm query-builder

我收到[Semantical Error] line 0, col 57 near 'room FROM AppBundle:bookings': Error: Invalid PathExpression. Must be a StateFieldPathExpression.的错误 AppBundle中有两个实体,分别是Room和Bookings。一旦我执行查询,我就会得到之前提到的错误。 我的查询在这里:

$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'));

1 个答案:

答案 0 :(得分:0)

我认为问题在于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'));