⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

multiple select filter doesnt work



crocerylover
  • profile picture
  • Member

Posted 13 April 2019 - 15:09 PM

hello friends 

 

i bought the crocery crud entreprise , i have a case when i did a n to n relation on 3 tables .

when im trying to filter the list based on the field that gives multiples values it doesnt work .

it has to be some sort of bug , its the same bug even on the online demo 

 

can everybody solve this prob plz 


crocerylover
  • profile picture
  • Member

Posted 08 May 2019 - 01:43 AM

the prob is in this line

 

 

    public function whereStatements($select)
    {
        if ($this->_filters) {
            foreach ($this->_filters as $filterName => $filter) {
                if ($this->isFieldWithRelationNtoN($filterName)) {
                    $rel = $this->_relation_n_n[$filterName];
 
                    $select->join($rel->junctionTable,
                        $rel->junctionTable . '.' . $rel->primaryKeyJunctionToCurrent . '=' .
                        $this->tableName . '.' . $this->getPrimaryKeyField($this->tableName). '',
                        []
                    );
 
                    if (is_array($filter)) {
                        $predictateSetArray = [];
                        foreach ($filter as $primaryKeyId) {
                            $predictateSetArray[] = new Predicate\Operator(
                                $rel->junctionTable . '.' . $rel->primaryKeyToReferrerTable, '=' , $primaryKeyId
                            );
                        }
 
                        if (!empty($predictateSetArray)) {
                            $select->where(new Predicate\PredicateSet($predictateSetArray, PredicateSet::OP_OR));
                        }
                    } else {
                        $select->where([
                            $rel->junctionTable . '.' . $rel->primaryKeyToReferrerTable => $filter
                        ]);
                    }
 
                }
            }
 
            // @todo: Remove duplicate code with the above filters
        } else if ($this->_filters_or) {
            foreach ($this->_filters_or as $filterName => $filter) {
                if ($this->isFieldWithRelationNtoN($filterName)) {
                    $rel = $this->_relation_n_n[$filterName];
 
                    $select->join($rel->junctionTable,
                        $rel->junctionTable . '.' . $rel->primaryKeyJunctionToCurrent . '=' .
                        $this->tableName . '.' . $this->getPrimaryKeyField($this->tableName). '',
                        []
                    );
 
                    if (is_array($filter)) {
                        $predictateSetArray = [];
                        foreach ($filter as $primaryKeyId) {
                            $predictateSetArray[] = new Predicate\Operator(
                                $rel->junctionTable . '.' . $rel->primaryKeyToReferrerTable, '=' , $primaryKeyId
                            );
                        }
 
                        if (!empty($predictateSetArray)) {
                            $select->where(new Predicate\PredicateSet($predictateSetArray, PredicateSet::OP_OR));
                        }
                    } else {
                        $select->where([
                            $rel->junctionTable . '.' . $rel->primaryKeyToReferrerTable => $filter
                        ]);
                    }
 
                }
            }
        }

 

on the first if , we can see clear that the operator is OP_OR . it should be and operator .and even ,the prob is still because the query is wrong . plz  i need a fix to this . ty for your help