protected function addAttributesSearchConditions(\yii\db\ActiveQuery $query)
    {
        $tablePrefix = $this->getDb()->getSchema()->quoteSimpleTableName('t');
        $conditions = ['and'];
        $formats = $this->attributeFormats();
        $attributes = $this->attributes();
        $relations = $this->relations();
        $validAttributes = array_diff($attributes, array_keys($this->getErrors()));
        $attributeValues = $this->getAttributes($validAttributes);
        $formatter = Yii::$app->formatter;
        /** @var EnumCollection $enums */
        $enums = $formatter instanceof Formatter ? $formatter->getEnums() : null;
        foreach ($validAttributes as $attribute) {
            $value = $attributeValues[$attribute];
            if ($value === null || !isset($formats[$attribute])
                || ($enums !== null && !is_array($formats[$attribute]) && $enums->has($formats[$attribute]))
            ) {
                continue;
            }

            if (in_array($attribute, $relations)) {
                // only hasMany relations should be ever marked as valid attributes
                $conditions[] = $this->getRelationCondition($this->getRelation($attribute), $value);
            } else {
                $conditions[] = $this->getAttributeCondition($attribute, $value, $formats, $tablePrefix, $this->getDb());
            }
        }
        // don't clear attributes to allow rendering filled search form
        //$this->setAttributes(array_fill_keys($attributes, null));
        if ($conditions !== ['and']) {
            $query->andWhere($conditions);
        }
        return $query;
    }
protected function addAttributesSearchConditions(\yii\db\ActiveQuery $query)
    {
        $tablePrefix = $this->getDb()->getSchema()->quoteSimpleTableName('t');
        $conditions = ['and'];
        $formats = $this->attributeFormats();
        $attributes = $this->attributes();
        $relations = $this->relations();
        $validAttributes = array_diff($attributes, array_keys($this->getErrors()));
        $attributeValues = $this->getAttributes($validAttributes);
        $formatter = Yii::$app->formatter;
        /** @var EnumCollection $enums */
        $enums = $formatter instanceof Formatter ? $formatter->getEnums() : null;
        foreach ($validAttributes as $attribute) {
            $value = $attributeValues[$attribute];
            if ($value === null || !isset($formats[$attribute])
                || ($enums !== null && !is_array($formats[$attribute]) && $enums->has($formats[$attribute]))
            ) {
                continue;
            }

            if (in_array($attribute, $relations)) {
                // only hasMany relations should be ever marked as valid attributes
                $conditions[] = $this->getRelationCondition($this->getRelation($attribute), $value);
            } else {
                $conditions[] = $this->getAttributeCondition($attribute, $value, $formats, $tablePrefix, $this->getDb());
            }
        }
        // don't clear attributes to allow rendering filled search form
        //$this->setAttributes(array_fill_keys($attributes, null));
        if ($conditions !== ['and']) {
            $query->andWhere($conditions);
        }
        return $query;
    }
protected function addAttributesSearchConditions ( \ yii \ db \ ActiveQuery $ query ) { $ tablePrefix = $ this -> getDb ( ) -> getSchema ( ) -> quoteSimpleTableName ( 't' ) ; $ conditions = [ 'and' ] ; $ formats = $ this -> attributeFormats ( ) ; $ attributes = $ this -> attributes ( ) ; $ relations = $ this -> relations ( ) ; $ validAttributes = array_diff ( $ attributes , array_keys ( $ this -> getErrors ( ) ) ) ; $ attributeValues = $ this -> getAttributes ( $ validAttributes ) ; $ formatter = Yii :: $ app -> formatter ; /** @var EnumCollection $enums */ $ enums = $ formatter instanceof Formatter ? $ formatter -> getEnums ( ) : null ; foreach ( $ validAttributes as $ attribute ) { $ value = $ attributeValues [ $ attribute ] ; if ( $ value === null || ! isset ( $ formats [ $ attribute ] ) || ( $ enums !== null && ! is_array ( $ formats [ $ attribute ] ) && $ enums -> has ( $ formats [ $ attribute ] ) ) ) { continue ; } if ( in_array ( $ attribute , $ relations ) ) { // only hasMany relations should be ever marked as valid attributes $ conditions [ ] = $ this -> getRelationCondition ( $ this -> getRelation ( $ attribute ) , $ value ) ; } else { $ conditions [ ] = $ this -> getAttributeCondition ( $ attribute , $ value , $ formats , $ tablePrefix , $ this -> getDb ( ) ) ; } } // don't clear attributes to allow rendering filled search form //$this->setAttributes(array_fill_keys($attributes, null)); if ( $ conditions !== [ 'and' ] ) { $ query -> andWhere ( $ conditions ) ; } return $ query ; }
Use a distinct compare value for each column. Primary and foreign keys support multiple values.
@param \yii\db\ActiveQuery $query
@return \yii\db\ActiveQuery
Use a distinct compare value for each column . Primary and foreign keys support multiple values .