{@inheritDoc}

Look for virtual columns in query's WHERE clause.

@param \Cake\ORM\Query $query The query to scope
@param string|null $bundle Consider attributes only for a specific bundle
@return \Cake\ORM\Query The modified query object
553973
public function scope(Query $query, $bundle = null)
    {
        $orderClause = $query->clause('order');
        if (!$orderClause) {
            return $query;
        }

        $class = new \ReflectionClass($orderClause);
        $property = $class->getProperty('_conditions');
        $property->setAccessible(true);
        $conditions = $property->getValue($orderClause);

        foreach ($conditions as $column => $direction) {
            if (empty($column) ||
                in_array($column, (array)$this->_table->schema()->columns()) || // ignore real columns
                !in_array($column, $this->_toolbox->getAttributeNames())
            ) {
                continue;
            }

            $conditions['(' . $this->_subQuery($column, $bundle) . ')'] = $direction;
            unset($conditions[$column]);
        }

        $property->setValue($orderClause, $conditions);

        return $query;
    }
41936
public function scopeWithGroup(Builder $query, string $group = null): Builder
    {
        return $group ? $query->where('group', $group) : $query;
    }
823444
protected function _where($query)
    {
        $link = null;
        $type_check = true;

        if ($query instanceof AnConfig) {
            $type_check = false;
            $query = $query->query;
        }

        $description = $query->getRepository()->getDescription();
        $clauses = array();
        if ($description->getInheritanceColumn() && $type_check) {
            $resource = $description->getInheritanceColumn()->resource->getAlias();
            //the table type column name
            $type_column_name = $resource.'.'.$description->getInheritanceColumn()->name;

            $scopes = AnConfig::unbox($query->instance_of);
            if (empty($scopes)) {
                $scopes = array($description);
            } else {
                if (!is_array($scopes)) {
                    $scopes = array($scopes);
                }
            }

            foreach ($scopes as $index => $scope) {
                $inheritance_type = $this->_inheritanceTree($scope);
                if (!empty($inheritance_type) && $inheritance_type != '%') {
                    $operator = substr($inheritance_type, -1) == '%' ? 'LIKE' : '=';
                    $scopes[$index] = $type_column_name.' '.$operator.' \''.$inheritance_type.'\'';
                } else {
                    unset($scopes[$index]);
                }
            }
            if (!empty($scopes)) {
                $clauses[] = '('.implode(' OR ', $scopes).')';
            }
        }

        if (!empty($query->where)) {
            $clause = '';
            foreach ($query->where as $where) {
                $clause .= $this->_buildWhere($query, $where);
            }
            if (!empty($clause)) {
                $clauses[] = '('.$clause.')';
            }
        }

        foreach ($query->link as $link) {
            $clauses = array_merge($clauses, $this->_where($link));
        }

        return $clauses;
    }
732567
public function scopePositioned($query)
    {
        $query->orderBy($this->getTable().'.position', 'asc');
        if ($this->usesTimestamps()) {
            $query->orderBy($this->getTable().'.created_at', 'desc');
        }
        return $query;
    }
564068
public function query($q = null)
    {
        return User::where(function ($query) use ($q) {
            $query->where('email', 'like', "%{$q}")
                ->orWhere('name', 'like', "%{$q}");
        })->orderBy('email')->paginate();
    }
1241508
protected function whereColumn(Builder $query, $where)
    {
        return $this->wrap($where['first']).' '.$where['operator'].' '.$this->wrap($where['second']);
    }
1212462
public function query($query=null)
    {
        if (!static::isSql($query)) {
            $this->checkQuery($query);
            $query = null;
        }
        
        return $this->getDb()->setQuery($this->getQuery())->query($query);
    }
623702
public function process(QueryInterface $query)
    {
        if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_TABLE_STATUS) {
            return null;
        }

        $likeExpr = $query->getLikeExpression();
        $tablet = $this->tablet->getTablet();
        $command = new GetSchema($tablet->getAlias());
        /* @var $vtCtldResult GetSchemaResult */
        $vtCtldResult = $this->client->executeCommand($command);

        return new TableStatus($vtCtldResult, $likeExpr);
    }
1356775
public function scopeFilter($query, $request)
    {
        $request = Arr::only($request, ['name', 'description']);

        $query->actives()->where(function ($query) use ($request) {
            foreach ($request as $key => $value) {
                $query->orWhere($key, 'like', '%' . $value . '%');
            }
            return $query;
        });

        return $query;
    }
812864
public function withQuery(string $query): URI
    {
        $result = clone $this;
        $result->query = $this->filterQuery($query);

        return $result;
    }
498051
public function applyScopes(ActiveQuery $query) {
        $value = $this->getValue();
        if ($value) {
//            if ($this->isPartially) {
//                $value = '%' . $value . '%';
//            }

            $attribute = $this->attribute;
            if (($db = $this->model->getDb()) && ($schema = $db->getSchema()) && $schema instanceof Schema) {
                $operator = 'LIKE';
            } else {
                $operator = 'ILIKE';
            }

            $query->andWhere([
                $operator,
                $attribute,
                $value,
            ]);
        }

        return $query;
    }
948935
protected function loadByQuery(Query $query)
    {
        $result = $this->doQuery($query);

        if ($result->getNumRows() == 0) {
            return null;
        }

        $this->fillProperties($result->fetch());

        return $this;
    }
250251
public function applyToRelationQuery($query, $table)
    {
        if (is_null($this->scope)) {
            return $query;
        }

        return $this->applyToQuery($query, $table);
    }
637413
public function setBundle(AbstractBundle $bundle)
    {
        $data = $bundle->getValues();
        foreach ($data as $name => $value) {
            $query = $this->getNewQuery();
            $query = $bundle->makeQueryFiltered($query);
            $setting = $query->firstOrNew(['name' => $name]);
            $setting->value = $value;
            $setting->save();
        }
    }
717916
private static function getCanonicalQuery($query = '')
    {

        if (empty($query)) {
            return $query;
        }

        $queryArray = self::encodeQueryParts($query);

        ksort($queryArray);

        $query = self::buildQuery($queryArray);

        return $query;
    }
97618
public function query($query, $type = '')
    {
        try {
            if ($type === 'SELECT') {
                return $this->conn->query($query);
            }

            return $this->conn->exec($query);
        } catch (\PDOException $e) {
            $this->error = $e->getMessage();

            return null;
        }
    }
23785
public function apply(Query $query) : Query
    {
        return $query->where(
            (new QueryExpression())->gt(
                $this->field,
                $this->value,
                $query->getTypeMap()->type($this->field)
            )
        );
    }