Return all models that have the selected attributes.
@param string [string] $attributes
@param null|string|ModelCondition $condition
@param array $params
@return static[]
336033
public static function findAllByAttributes($attributes, $condition = null, $params = [])
    {
        $class = get_called_class();
        $condition = ModelCondition::getFrom($condition, $class);
        foreach ($attributes as $name => $value) {
            $condition->compareColumn($name, $value);
        }
        return self::findAll($condition, $params);
    }
910803
public function where(string $condition = '', array $params = []) {
        if ($condition) {
            $this->sql .= " WHERE $condition ";
            $this->params = array_merge($this->params, $params);
        }
        return $this;
    }
1201616
public function already_selected($attribute, $params)
    {
        if($this->$attribute && $this->find()->where($attribute . '=' . $this->$attribute . 
            ($this->id ? ' and id <> ' . $this->id : '')
        )->one())
            $this->addError($attribute, $params['message']);
    }
273042
public static function extractAttributes(array $attributes): array
    {
        $result = ['resource_class' => $attributes['_api_resource_class'] ?? null];
        if ($subresourceContext = $attributes['_api_subresource_context'] ?? null) {
            $result['subresource_context'] = $subresourceContext;
        }

        if (null === $result['resource_class']) {
            return [];
        }

        $hasRequestAttributeKey = false;
        foreach (OperationType::TYPES as $operationType) {
            $attribute = "_api_{$operationType}_operation_name";
            if (isset($attributes[$attribute])) {
                $result["{$operationType}_operation_name"] = $attributes[$attribute];
                $hasRequestAttributeKey = true;
                break;
            }
        }

        if (false === $hasRequestAttributeKey) {
            return [];
        }

        $result += [
            'receive' => (bool) ($attributes['_api_receive'] ?? true),
            'respond' => (bool) ($attributes['_api_respond'] ?? true),
            'persist' => (bool) ($attributes['_api_persist'] ?? true),
        ];

        return $result;
    }
737077
public function andWhere($condition, $params = [])
    {
        if (is_array($condition)) {
            foreach ($condition as $key => $value) {
                if ($this->canSetProperty($key)) {
                    $this->{$key} = $value;
                    unset($condition[$key]);
                }
            }
        }

        return parent::andWhere($condition);
    }
492938
public function buildHashCondition($condition, &$params)
    {
        $parts = [];

        foreach ($condition as $column => $value) {
            if (ArrayHelper::isTraversable($value) || $value instanceof Query) {
                // IN condition
                $parts[] = $this->buildInCondition('IN', [$column, $value], $params);
            }
            else {
                if (strpos($column, '(') === false) {
                    $column = $this->db->quoteColumnName($column);
                }

                if ($value === null) {
                    $parts[] = "$column IS NULL";
                }
                elseif ($value instanceof Expression) {
                    $parts[] = "$column=" . $value->expression;

                    foreach ($value->params as $n => $v) {
                        $params[$n] = $v;
                    }
                }
                else {
                    $phName = self::PARAM_PREFIX . count($params);
                    $parts[] = "$column=$phName";
                    $params[$phName] = $value;
                }
            }
        }

        return count($parts) === 1 ? $parts[0] : '(' . implode(') AND (', $parts) . ')';
    }
301990
public function getOrCreate(array $attributes)
    {
        $model = $this->get($attributes);
        if (null === $model) {
            $className = get_class($this->getModel());
            /** @var Model $model */
            $model = new $className($attributes);
            $model->save();

            return [$model, true];
        }

        return [$model, false];
    }
449799
protected function stateAttributes($state, array $attributes)
    {
        $stateAttributes = $this->states[$this->class][$state];

        if (! is_callable($stateAttributes)) {
            return $stateAttributes;
        }

        return call_user_func(
            $stateAttributes,
            $this->faker, $attributes
        );
    }
615814
private function getAttributeValues($attribute, $attributeValues)
    {
        $values = [];
        foreach ($attributeValues as $attributeValue) {
            if ($attribute['id'] == $attributeValue['attributeId']) {
                $values[] = $attributeValue;
            }
        }

        return $values;
    }
1066631
public static function findAll(string $className, array $condition = [], array $options = [])
    {
        $instance = self::getInstance($className);
        $query    = Query::table($className)->className($className)->selectInstance($instance);

        if (!empty($condition)) {
            $query = $query->condition($condition);
        }

        $query  = self::applyOptions($query, $options);
        $fields = self::getFieldsFromOptions($options);

        return $query->get($fields);
    }
555950
public function delete($condition=null, $params=null) {
		return $this->driver->delete($condition, $params);
	}
475537
public function one(string $condition = '', array $params = []) {
        X::logger()->trace('Redis cached one');
        $key = $this->getOneKey($condition, $params);
        $pk = $this->redis()->get($key);
        if ($pk) {
            X::logger()->trace("Hit one $key");
            return $this->load($pk);
        }

        X::logger()->trace("Miss one $key");
        $model = DirectModelManager::getInstance($this->model)
            ->one($condition, $params);
        if ($model) {
            $this->set(
                $key,
                $model->pk,
                $this->conf['duration']['one']
            );
            $this->poolSet($model);
        }
        X::logger()->trace("Saved one $key");
        return $model;
    }
505510
public static function find($condition, $params = array())
    {
        if (!is_a($condition, '\\mpf\\datasources\\sql\\ModelCondition'))
            $condition = ModelCondition::getFrom($condition, get_called_class());

        /* @var $condition \mpf\datasources\sql\ModelCondition */
        $oldLimit = $condition->limit;
        $condition->limit = 1;
        $models = static::findAll($condition, $params);
        $condition->limit = $oldLimit;
        return isset($models[0]) ? $models[0] : null;
    }
347331
protected function arrayToConditions($conditions)
    {
        $ret = [];

        foreach ($conditions as $key => $value) {
            if ($value instanceof Condition) {
                $ret[] = $value;
                continue;
            }

            $propertyOperator = explode('-', $key);

            if (in_array(count($propertyOperator), [1, 2])) {
                $ret[] = new Condition($propertyOperator[0], $value, $propertyOperator[1] ?? null);
            }
        }

        return $ret;
    }
557770
public static function getFrom($condition, $model) {
        if (is_a($condition, '\\mpf\datasources\\sql\\ModelCondition')) {
            $condition->model = $model;
            return $condition;
        }
        if (is_array($condition) && count($condition))
            $cond = new static($condition);
        else {
            $cond = new static;
            if ($condition)
                $cond->addCondition($condition);
        }
        $cond->model = $model;
        return $cond;
    }
1245098
public static function updateAll ($attributes , $condition = '' , $params = []) {
        $ret = parent::updateAll ($attributes , $condition , $params);
        if ($ret && self::allowFromCache($condition)) {
            $cache_key = self::getCacheKey($condition[static::$pk], true);
            Yii::trace('delete cache:'.$cache_key, __METHOD__);
            static::getCache()->delete($cache_key);
            $cache_key = self::getCacheKey($condition[static::$pk], false);
            static::getCache()->delete($cache_key);
        }
        return $ret;
    }
1064265
public function many(string $condition = '', array $params = array(), $offset = null, $limit = null) {
        $this->model->builder
            ->select('*')
            ->from($this->model->tableName);

        if ($condition) {
            $this->model->builder->where($condition, $params);
        }

        if (null !== $offset) {
            if (null === $limit) {
                $this->model->builder->limit($offset);
            } else {
                $this->model->builder->limit($offset, $limit);
            }
        }
        $r = $this->model->builder->query();
        if (!is_array($r) || 0 === count($r)) {
            return [];
        }

        return $this->model->setup($r);
    }