Convert raw sql to query object

Is there a way to convert a raw SQL statement into a query? My SQL statement is very complicated, it seems it is over of the capacity of the ORM.
I can run my raw SQL perhaps, but I bumped into some problems with the paginator in this case. So it seems I should convert it to a query object.

Any ideas?

Could you post the SQL ? We can try to create a ORM solution together :smiley:

I refactored my code and was able to do it with the ORM. Digging into the API revealed the other way is a dead end.