Invalid PathExpression. Must be a StateFieldPathExpression

若如初见. 提交于 2019-12-03 00:04:55

问题


I get an error which is [Semantical Error] line 0, col 57 near 'room FROM AppBundle:bookings': Error: Invalid PathExpression. Must be a StateFieldPathExpression. I have two entities in AppBundle which are Room and Bookings. once I execute the query I get the error mentionned before. Here my query :

$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:


I think the problem is about the WHERE NOT. try with this query:

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


来源:https://stackoverflow.com/questions/47872448/invalid-pathexpression-must-be-a-statefieldpathexpression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!