Zend Sql: Adding a new Where object to A Select Object that already has where clauses causes the pre-existing where clauses to be removed

I'm using the following code to build a query based on the GET request parameters as part of a REST service:

foreach($params as $key=>$param) {
    if($key != 'page' && $key != 'pageSize' && $key != 'likeStart' && $key != 'likeEnd') {
        if(strpos($param, ',') !== false) {
            $where = new \Zend\Db\Sql\Where();

            $predicate_set = $where->nest();
            $param_arr = explode(',', $param);

            $entered_once = 0;
            foreach($param_arr as $p) {
                $field = str_replace("_", ".", $key);
                if(!$like) {       
                    $arr[$field]['egal'] = $p;
                    $predicate_set->equalTo($field, $p);
                }
                else {
                    $predicate_set->like($field, "%$p%");
                    $arr[$field]['like'] = $p;
                }
                var_dump($predicate_set);

                if($entered_once < count($param_arr)) {
                    $predicate_set->or;
                }
                $entered_once++;
            }

            $predicate_set->unnest();
            $select->where($where);
        }
        else {
            $field = str_replace("_", ".", $key);
            if(!$like) {
                $select->where->equalTo($field, $param);
                $arr[$field]['egal'] = $param;
            }
            else {
                $select->where->like($field, "%$param%");
                $arr[$field]['like'] = $param;
            }
        }
    }    
    else if($key == 'likeStart') {                  
        $like = true;
    }   
    else if($key == 'likeEnd') {
        $like = false;
    }       
}

the problem with it is that after the line $select->where($where); Everything I previously had in the Where clause (or object) on the select is replaced with the new Where predicate. Is there a way to add the predicate to the existing object?

Answers


Hm, actually found the answer while looking through the Zend docs. Using $select->where->addPredicate($where) instead of $select->where($where) causes the query to be built correctly.

Gonna leave the question up in case other people are facing the same problem (god knows no one in the office knew how to do it)


Need Your Help

Overlaying actual data on a boxplot from a pandas dataframe

matplotlib pandas dataframe boxplot seaborn

I am using Seaborn to make boxplots from pandas dataframes. Seaborn boxplots seem to essentially read the dataframes the same way as the pandas boxplot functionality (so I hope the solution is the ...

selectOneRadio with null value not displaying correctly (Mojarra 2.1.28)

jsf el

I have a Boolean that is set with a selectOneRadio tag as follows: