We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PHQL wrong parsing with subquery

Hi.

I use query builder with subquery in conditions. It created this PHQL

SELECT hotel.id AS [hotel_id], hotel.name AS [hotel_name], hotel.full_sort AS [full_sort], hotel.our_sort AS [our_sort], hotel.rate AS [rate], geo_request_hotels.distance AS [distance] FROM [\My\Models\Hotel] AS [hotel] JOIN [m:SearchGeoRequestHotels] AS [geo_request_hotels] ON geo_request_hotels.hotel_id = hotel.id JOIN [m:SearchGeoRequest] AS [geo_request] ON geo_request.id = geo_request_hotels.request_id WHERE geo_request.hash = 'fcc05f879a29018badc45fee03ca2182ff726930e5475da53a07bc242fc8992b' AND hotel.id IN (SELECT he.hotel FROM [\My\Models\HotelEquip] AS [he] WHERE he.equip = 56) ORDER BY [full_sort] DESC

When I try to run it I get error:

Phalcon\Mvc\Model\Exception: Can't obtain model's source from models list: 'My\Models\Hotel', when preparing ...

So if a remove square brackets from [\My\Models\Hotel] it runs perfectly. Or I remove subquery "hotel.id IN (SELECT he.hotel FROM [\My\Models\HotelEquip] AS [he] WHERE he.equip = 56)". It also runs perfectly. So the problem is in parsing and dealing with subqueries.

I can't get rid of query builder since I use pagination query builder adapter. Any suggestions? It seems a bug.

I think IN() is not part of PHQL extend your dialect see this example



519

No, IN() is a part. As I mentioned as soon as I remove square brackets from first model [\My\Models\Hotel] the problem is gone.

I think IN() is not part of PHQL extend your dialect see this example

What do the brackets do? never used them before