leandrogehlen / yii2-querybuilder

Extension for Yii2 Framework to work with jQuery QueryBuilder
42 stars 34 forks source link

Feature request: multiple queries merged #6

Closed TonisOrmisson closed 5 years ago

TonisOrmisson commented 8 years ago

Hi,

I'd like to propose an additional feature.

I have a situation where I need to add multiple query-builder objects into one query. But what happens now is that the params in the Query are shared. I have code like that:

$query = new Query;
foreach ($my->usedFilters as $qhf) {
    $rules = Json::decode($qhf->questionFilter->filter);
    $translator = new Translator($rules);
    $query
            ->andWhere($translator->where())
            ->addParams($translator->params());
}

What happens here is that the params in Query is for the whole query. With each loop the params will be reassigned as p0, p1 .. pn and with each loop they get overwritten.

So I am thinking that the Translator could have something like setCurrentParams($params) where you could set the already assigned params and the next ones would be added on top rather than overwritten.

so we would have code like that for my implementation

$query = new Query;
foreach ($my->usedFilters as $qhf) {
    $rules = Json::decode($qhf->questionFilter->filter);
    $translator = new Translator($rules);
    $translator->setCurrentParams($query->params);
    $query
            ->andWhere($translator->where())
            ->addParams($translator->params());
}
TonisOrmisson commented 8 years ago

I did a test in my fork here https://github.com/andmemasin/yii2-querybuilder I's an initial test so probably some work still needed for that