@param string     $modelClass
@param array      $criteria
@param array|null $orderBy

@return ModelInterface|null
186222
public function findOneBy(string $modelClass, array $criteria, array $orderBy = null)
    {
        return $this->getRepositoryByClass($modelClass)->findOneBy($criteria, $orderBy);
    }
1149559
public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof UserQuery) {
            return $criteria;
        }
        $query = new UserQuery(null, null, $modelAlias);

        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }
1165680
public function find($class, Criteria $criteria=null)
    {
        return new Collection($class,
            $this->query($criteria, $this->_pheasant->schema($class)->alias()));
    }
789875
public function findOneBy(array $criteria, array $orderBy = null)
    {
        $criteria = array_merge($criteria, array("deleted" => false));

        return parent::findOneBy($criteria, $orderBy);
    }
1021599
public function select($table, $where, $orderBy = null)
    {
        return $this->fieldSelect($table, "*", $where, $orderBy);
    }
477506
protected function getQueryBuilderForModelClass($modelClass)
    {
        if ( ! is_a($modelClass, Model::class, true)) {
            throw new UnexpectedValueException("{$modelClass} is not an Eloquent model.");
        }

        // If the targeted model is a CMS model, we can default back to its reference data
        // if not specifics are given, otherwise, a custom fallback reference must be used.
        if ($info = $this->getCmsModelInformation($modelClass)) {

            // Get model records, filtered as necessary
            $repository = $this->getModelRepositoryForInformation($info);

            /** @var Model[] $models */
            return $repository->query();
        }

        // The model is not part of the CMS
        return $this->getQueryBuilderForNonCmsModelClass($modelClass);
    }
30567
public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null)
    {
        $pool       = $this->manager->getPool();
        $manager_id = $this->class->getManagerIdentifier();

        $models = array();
        foreach ($this->class->getFieldManagerNames() as $manager) {
            $models[$manager] = $this->class->getFieldMapping($manager)->getName();
        }

        $data = $pool->getManager($manager_id)->getRepository($models[$manager_id])->findBy($criteria, $orderBy, $limit, $offset);

        if (empty($data)) {
            return array();
        }

        $builder = new ModelBuilder($this->manager, $this->uow, $this->class);

        return $builder->buildAll($data, $manager_id);
    }
425734
public static function hasMany($modelClass, $columnName, $options = []) {
        $options['type'] = self::HAS_MANY;
        $options['modelClass'] = $modelClass;
        $options['compares'] = [["t.__PK__", (false === strpos($columnName, '.')) ? "r.$columnName" : $columnName, "="]];
        return new self($options);
    }
598445
public function getOneEntityBy(array $criteria = [], array $orders = [], $offset = null): ?AbstractEntity
    {
        $entity = $this->getRepository()->findOneBy($criteria, $orders, $offset);

        if ($entity instanceof AbstractEntity) {
            $this->prepareEntityForGet($entity);
        }

        return $entity;
    }
1057476
public function findRelation($entity, $relationName, $orderColumn = null, $orderType = null) {
        $this->load();
        $mapper = MapperBuilder::buildFromClassName($this->mapping, get_class($entity));
        $relation = $mapper->getRelation($relationName);
        $relationMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());

        $selectQuery = "SELECT tmain.* FROM `" . $relationMapper->getTable() . "` tmain ";
        $joinQuery = QueryBuilder::buildJoinRelationQuery($relation, "tmain", "j1");
        $whereQuery = "WHERE j1." . $relation->getLocalColumn() . " = '" . $entity->getId() . "'";

        $orderQuery = "";
        if (!is_null($orderColumn)) {
            $orderQuery .= "ORDER BY $orderColumn ";
            if (!is_null($orderType)) {
                $orderQuery .= "$orderType";
            } else {
                $orderQuery .= "ASC";
            }
        }

        $query = $selectQuery . $joinQuery . $whereQuery . $orderQuery;
        $queryResult = $this->getDataSource()->query($query);
        if ($queryResult) {
            $collection = new Collection($relationMapper->getClass(), $queryResult, $relationMapper);
        } else {
            $collection = new Collection($relationMapper->getClass(), array(), $relationMapper);
        }

        return $collection;
    }
734215
public function findBy(
        array $criteria,
        ?array $orderBy = null,
        ?int $limit = null,
        ?int $offset = null
    ) : array {
        $rows = [];

        foreach ($this->getSourceRows() as $row) {
            if (! $this->matches($criteria, $row)) {
                continue;
            }

            $rows[] = $row;
        }

        if ($orderBy !== null && $orderBy !== []) {
            $rows = $this->sort($rows, $orderBy);
        }

        if ($limit !== null || $offset !== null) {
            return $this->slice($rows, $limit, $offset);
        }

        return $rows;
    }
1092409
public function complexFindBy(array $criteria, array $orderBy = [], $limit = null, $offset = null)
    {
        $qb = $this->createQueryBuilder("p");

        foreach($criteria as $c => $v){
            $qb->andWhere("p.$c $v");
        }
        foreach($orderBy as $c => $v){
            $qb->addOrderBy("p.".$c,$v);
        }
        if (isset($limit)) $qb->setMaxResults($limit);
        if (isset($offset)) $qb->setFirstResult($offset);

        return $qb->getQuery()->getResult();
    }
1139192
final public static function all($orderBy = ['createdAt' => 'DESC'], bool $withTrash = false)
    {
        $criteria = self::criteriaWithSoftDelete([], $withTrash);
        return static::getRepository()
            ->findBy($criteria, $orderBy);
    }
553817
public function findOne($conditions, string $orderBy = null): Result
    {
        $query = $this->query()
            ->where($conditions)
            ->limit(1);

        if ($orderBy) {
            $query->orderBy($orderBy);
        }

        return $query->query();
    }
1079709
private function filterAndSortByEncryptedField(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $encryptedSort = $this->orderByHasEncryptedField($orderBy);

        $encryptedFields = $this->getEncryptedFields();
        $notEncryptedCriteria = array_diff_key($criteria, $encryptedFields);
        $notEncryptedOrderBy = !$encryptedSort ? $orderBy : null;

        // Get the result of the filter by not encrypted fields
        $result = $this->wrapped->findBy($notEncryptedCriteria, $notEncryptedOrderBy);

        $encryptedCriteria = array_intersect_key($criteria, $encryptedFields);
        if (!empty($result) && !empty($encryptedCriteria)) {
            $result = $this->filterWithEncryptedCriteria($result, $encryptedCriteria);
        }

        if ($encryptedSort && !empty($orderBy)) {
            $result = $this->sortWithEncryptedOrderBy($result, $orderBy);
        }

        if ($limit) {
            $offset = $offset ? $offset : 0;

            $result = array_slice($result, $offset, $limit);
        }

        return $result;
    }
971796
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $this->preFindBy($criteria);

        $result =  $this->doFindBy($criteria, $orderBy, $limit, $offset);
        $result = $this->postFindBy($result);

        return $result;
    }
472644
protected function sort(ModelCriteria $query, Request $request)
    {
        $order = $this->getSortOrder($request);

        foreach ($order as $setting) {
            $column = $setting[0];
            $direction = $setting[1];
            $query->orderBy($column, $direction);
        }

        return $query;
    }