We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Nested PHQL Query Conditions with Query Builder

Is there a way to nest/group conditions with the OO PHQL query builder?

Say in raw SQL you have SELECT id, name FROM table WHERE (id = 1 AND name = 2) OR (id = 1 AND name = 3)

With the query builder $queryObj->from('table') ->columns(array('id','name')) ->where('id = 1') ->andWhere('name = 2') ->orWhere(...) // nesting/grouping breaks down/un-expected nesting after this point


Try specifying more than one condition within a single where block:

   ->where('id = 1 AND xx = 2')
   ->orWhere('id = 2 AND xx = 1');