-1

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'));
Mostafa
  • 63
  • 2
  • 11
  • I think the problem is about the `WHERE NOT` – Matteo Dec 18 '17 at 16:46
  • 1
    Possible duplicate of ["Invalid PathExpression. Must be a StateFieldPathExpression" in query builder with non related entities](https://stackoverflow.com/questions/22666692/invalid-pathexpression-must-be-a-statefieldpathexpression-in-query-builder-wi) – ReynierPM Dec 18 '17 at 19:05

1 Answers1

0

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'));
Matteo
  • 37,680
  • 11
  • 100
  • 115