Return a single class for a single row;
@param mixed $condition
@param string[] $params
@return static
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;
    }
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);
    }
562972
public function search($params, $status = null)
    {
        $order = (empty($status)) ? Order::find()->where(['user_id' => \Yii::$app->user->id])->one() :
            Order::find()->where(['user_id' => \Yii::$app->user->id, 'status' => $status])->one();

        if (!empty($order)) {
            $query = OrderProduct::find();

            // add conditions that should always apply here

            $dataProvider = new ActiveDataProvider([
                'query' => $query,
            ]);

            $this->load($params);

            if (!$this->validate()) {
                // uncomment the following line if you do not want to return any records when validation fails
                // $query->where('0=1');
                return $dataProvider;
            }

            // grid filtering conditions
            $query->andFilterWhere([
                'id' => $this->id,
                'product_id' => $this->product_id,
                'order_id' => $order->id,
                'count' => $this->count,
            ]);

            return $dataProvider;
        }


    }
780786
public function many(string $condition = '', array $params = array(), $offset = null, $limit = null) {
        X::logger()->trace('Redis cached many');
        $key = $this->getManyKey($condition, $params, $offset, $limit);
        /** @var array $pks */
        /** @noinspection UnserializeExploitsInspection */
        $pks = @unserialize($this->redis()->get($key));
        if (is_array($pks)) {
            X::logger()->trace("Hit many $key");
            return $this->pks2models($pks);
        }

        X::logger()->trace("Miss many $key");
        return $this->manySet($key,
            DirectModelManager::getInstance($this->model)
                ->many($condition, $params, $offset, $limit)
        );
    }
609630
public function count(string $condition = '', array $params = array()) {
        $this->model->builder->select('COUNT(*)')
            ->from($this->model->tableName);
        if ($condition) {
            $this->model->builder->where($condition, $params);
        }
        $r = $this->model->builder->query();
        if (!is_array($r) || 0 === count($r)) {
            return false;
        }
        return (int) reset($r[0]);
    }
914345
public function findOne($conditions, $params = array()){
        $row = $this->db->builder()->select()->from($this->table)->where($conditions, $params)->limit(1)->queryRow();
        if(false === $row){
            return false;
        }
        
        return $this->map($row);
    }
1224916
public function update($data, $params, $condition = "id")
	{
		$affected = parent::update($data, $params, $condition);
		$this->recache();
		return $affected;
	}
306416
public static function deleteByPk($pk, $condition = null, $params = array())
    {
        if (!is_a($condition, '\\mpf\\datasources\\sql\\ModelCondition')) {
            $condition = ModelCondition::getFrom($condition, get_called_class());
        }
        /* @var $condition ModelCondition */
        $condition->compareColumn(static::getDb()->getTablePk(static::getTableName()), $pk);
        return static::deleteAll($condition, $params);
    }
1012471
public function fetch($condition = array())
    {
        $query = self::getInstance($this, $condition);

        return $this->getRepository()->fetch($query);
    }
1217526
public static function counts($condition = null, $params = null, $distinct=false) {
        return static::dao()->count(
            $condition,
            $params,
            $distinct
        );
    }
763147
public static function create($condition): self
    {
        $condition = $condition instanceof Condition ? $condition : Condition::fromValue($condition);

        return new self($condition);
    }
859920
public static function finds($condition = NULL, $rows = 0, $start = 0, $order='', $fields = '*', $object = true) {
        return static::dao($object)->finds($condition,$rows,$start,$order,$fields);
    }
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);
    }
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;
    }
124783
public static function deleteAllByAttributes($attributes, $condition = null, $params = array())
    {
        if (!is_a($condition, '\\mpf\\datasources\\sql\\ModelCondition')) {
            $condition = ModelCondition::getFrom($condition, get_called_class());
        }
        /* @var $condition ModelCondition */
        foreach ($attributes as $k => $v) {
            $condition->compareColumn($k, $v);
        }
        return static::deleteAll($condition, $params);
    }
958982
function where( $condition, $params = array() ) {

        $clone = clone $this;

        // conditions in key-value array
        if ( is_array( $condition ) ) {

            foreach ( $condition as $c => $params ) {

                $clone = $clone->where( $c, $params );

            }

            return $clone;

        }

        // shortcut for basic "column is (in) value"
        if ( preg_match( '/^[a-z0-9_.`"]+$/i', $condition ) ) {

            $clone->where[] = $clone->db->is( $condition, $params );

            return $clone;

        }

        if ( !is_array( $params ) ) {

            $params = func_get_args();
            array_shift( $params );

        }

        $clone->where[] = $condition;
        $clone->whereParams = array_merge( $clone->whereParams, $params );

        return $clone;

    }
1006783
public function count($conditions = '', $params = array()){
        return $this->db->builder()->select('COUNT(*)')->from($this->table)->where($conditions, $params)->queryValue();
    }