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

Combining QueryBuilders

I'm looking for a way to simplify building complex queries. So, for example I need to add a bunch of OR conditions to a larger AND condition. Ideally I could use a separate QueryBuilder instance to build the AND condition. For example:

$mainBuilder->andWhere('something = 1')

foreach ($array as $val)
{
    $subBuilder->orWhere($val . ' = 1');
}

$mainBuilder->andWhere($subBuilder);

Is there a way to use QueryBuilders like this? Any other suggestions on how to build complex queries using the QueryBuilder?

I don't think another Builder fits here, but it could be a Phalcon\Mvc\Model\Query\Builder\Condition-like class - shouldn't be too hard to create since it should basically concatenate some AND or OR strings.

Do you mind adding this feature request to github, so it can be tracked?