"active" find method
@param Query $query Query object
@param array $options Options
@return Query Query object
511464
public function findActive(Query $query, array $options)
    {
        return $query->innerJoinWith('Posts', function (Query $q) {
            return $q->find('active');
        })->distinct();
    }
516880
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
    {
        $field = $this->getTrashField();
        $addCondition = true;

        $query->traverseExpressions(function ($expression) use (&$addCondition, $field) {
            if (!$addCondition) {
                return;
            }

            if ($expression instanceof IdentifierExpression
                && $expression->getIdentifier() === $field
            ) {
                $addCondition = false;

                return;
            }

            if (($expression instanceof Comparison || $expression instanceof BetweenExpression)
                && $expression->getField() === $field
            ) {
                $addCondition = false;
            }
        });

        if ($addCondition) {
            $query->andWhere($query->newExpr()->isNull($field));
        }
    }
675346
public function queryAssoc($query, $options = array())
    {
        $statement = $this->_runQuery($query, $options);
        return $statement->fetch(\PDO::FETCH_ASSOC);
    }
435642
public function findKv(Query $query, array $options)
    {
        return $query
            ->find('list', [
                'keyField' => 'path',
                'valueField' => 'value',
                'groupField' => 'namespace',
            ])
            ->formatResults(function ($results) {
                $resultSet = $results->toArray();
                if (isset($resultSet[''])) {
                    $resultSet += $resultSet[''];
                    unset($resultSet['']);
                }

                return $resultSet;
            });
    }
1239294
public function beforeFind(Event $event, Query $query, $options, $primary) {
		$order = $query->clause('order');
		if (($order === null || !count($order)) && !empty($this->order)) {
			$query->order($this->order);
		}

		return $query;
	}
490952
public function findWithTrashed(Query $query, array $options)
    {
        return $query->where(['OR' => [
            $query->newExpr()->isNotNull($this->getTrashField()),
            $query->newExpr()->isNull($this->getTrashField()),
        ]]);
    }
797694
private function executeQuery($document, array $query, array $options)
    {
        $className  = get_class($document);
        $class      = $this->dm->getClassMetadata($className);
        $findQuery  = $this->getQueryForDocument($class, $document);
        $collection = $this->dm->getDocumentCollection($className);
        $collection->update($findQuery, $query, $options);
    }
934500
public function findOne(array $query = [], array $fields = [])
    {
        if ($this->eventManager->hasListeners(Events::preFindOne)) {
            $findEventArgs = new FindEventArgs($this, $query, $fields);
            $this->eventManager->dispatchEvent(Events::preFindOne, $findEventArgs);
            $query = $findEventArgs->getQuery();
            $fields = $findEventArgs->getFields();
        }

        $result = $this->doFindOne($query, $fields);

        if ($this->eventManager->hasListeners(Events::postFindOne)) {
            $eventArgs = new MutableEventArgs($this, $result);
            $this->eventManager->dispatchEvent(Events::postFindOne, $eventArgs);
            $result = $eventArgs->getData();
        }

        return $result;
    }
473412
protected function getPaginationData(Select $query, array $options)
    {
        // Get pagination options
        $page = (int) Arr::get($options, 'page');

        if ($page < 1) {
            $page = 1;
        }

        $resultsPerPage = Arr::get(
            $options,
            'resultsPerPage',
            $this->resultsPerPage
        );

        // Get total results
        $resultCount = $this->getQueryResultCount($query);
        $pageCount   = ceil($resultCount / $resultsPerPage);

        return new PaginationData([
            'page'             => $page,
            'page_count'       => $pageCount,
            'result_count'     => $resultCount,
            'results_per_page' => $resultsPerPage
        ]);
    }
145272
public function queryTable($query, $options = array())
    {
        return $this->queryArray($query, $options,
            function(\PDOStatement $statement) { return $statement->fetchAll(\PDO::FETCH_ASSOC); }
        );
    }
1164036
public function search($options = [])
    {
        $query = $this->queryParts;
        if (empty($query)) {
            $query = '{}';
        }
        if (is_array($query)) {
            $query = Json::encode($query);
        }
        $url = [$this->index !== null ? $this->index : '_all'];
        if ($this->type !== null) {
            $url[] = $this->type;
        }
        $url[] = '_search';

        return $this->db->get($url, array_merge($this->options, $options), $query);
    }
1074868
public function read($query, array $options = []) {
		$this->_checkConnection();

		$defaults = ['return' => 'resource'];
		$options += $defaults;

		$params = compact('query', 'options');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$prefix = $this->_config['gridPrefix'];

			$query = $params['query'];
			$options = $params['options'];
			$args = $query->export($this);
			$source = $args['source'];
			$model = $query->model();

			if ($group = $args['group']) {
				$result = $this->_group($group, $args, $options);
				$config = ['class' => 'set', 'defaults' => false] + compact('query') + $result;
				return $model::create($config['data'], $config);
			}
			$collection = $this->connection->{$source};

			if ($source === "{$prefix}.files") {
				$collection = $this->connection->getGridFS($prefix);
			}
			$result = $collection->find($args['conditions'], $args['fields']);

			if ($query->calculate()) {
				return $result;
			}

			$resource = $result->sort($args['order'])->limit($args['limit'])->skip($args['offset']);
			$result = $this->_instance('result', compact('resource'));
			$config = compact('result', 'query') + ['class' => 'set', 'defaults' => false];
			return $model::create([], $config);
		});
	}
417851
public function findAndModify(array $query, array $update = array(), array $fields = null, array $options = array())
    {
        $document = new Document($query, $this);
        $findAndModify = $document->findAndModify($update, $fields, $options);

        return $findAndModify;
    }
435254
public function search(\Cake\ORM\Query $query, $options = [])
    {
        $_query = $this->Controller->request->query;
        $this->Controller->request->data = $_query;

        $params = $_query;
        $filters = $this->_normalize($this->config('filters'));

        foreach ($filters as $field => $options) {
            $hash = Hash::get($params, $options['column']);
            if (!empty($hash)) {
                $key = $this->_buildKey($field, $options);
                $value = $this->_buildValue($field, $options, $params);

                $query->where([$key => $value]);

                $this->_setValue($field, $options, $params);
            }
        }

        return $query;
    }
1307963
public function findDeleted($query, $options)
    {
        $query->where([
            $this->config('field') => $this->config('states.deleted'),
        ]);

        return $query;
    }
151560
public function findSlugged(Query $query, array $options) {
		if (empty($options['slug'])) {
			throw new InvalidArgumentException("The 'slug' key is required for find('slugged')");
		}

		return $query->where([$this->_config['field'] => $options['slug']]);
	}
1230278
public function findRandom(Query $query, array $options)
    {
        $query->order('rand()');

        if (!$query->clause('limit')) {
            $query->limit(1);
        }

        return $query;
    }