Finds a single entity by a set of criteria.

@param mixed[] $criteria
@param mixed[] $orderBy

@return object|null The entity instance or NULL if the entity can not be found.
179916
public function findOneBy(array $criteria, array $orderBy = [])
    {
        $persister = $this->em->getUnitOfWork()->getEntityPersister($this->entityName);

        return $persister->load($criteria, null, null, [], null, 1, $orderBy);
    }
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;
    }
1254543
public function findBy(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null)
    {
        return $this->findAll();
    }
409304
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $criteria = array_merge($criteria, array("deleted" => false));

        return parent::findBy($criteria, $orderBy, $limit, $offset);
    }
1062453
public function findBy(array $criteria = [], array $orders = [], $limit = null, $offset = null): array
    {
        $options = [];

        if ($orders) {
            foreach ($orders as $field => &$dir) {
                if ($dir === 'ASC') {
                    $dir = 1;
                } elseif ($dir === 'DESC') {
                    $dir = -1;
                }

            }
            $options['sort'] = $orders;
        }

        if ($limit !== null) {
            $options['limit'] = $limit;
        }

        if ($offset !== null) {
            $options['skip'] = $offset;
        }

        $options['projection'] = [];

        /** @var Cursor $cursor */
        $cursor = $this->collection->find($criteria, $options);

        $ids = [];

        $data = iterator_to_array($cursor);

        array_walk($data, function($value, $key) use (&$ids) {
            $ids[] = $value['_id'];
        });

        return $this->findByIds($ids);
    }
292245
public function findOneBy(array $criteria)
    {
        $documents = $this->findBy($criteria, array(), 1);

        if ($documents instanceof ArrayCollection && count($documents)) {
            return $documents->first();
        }

        return null;
    }
213586
protected function applyOrderBy(array $data, $orderBy)
    {
        if (!empty($orderBy)) {
            ArrayHelper::multisort($data, array_keys($orderBy), array_values($orderBy));
        }

        return $data;
    }
230733
public function sortBy($criteria)
    {
        $criteria = $this->factoryCallableCriteria($criteria);
        $sorted   = $this->create();
        $groups   = $this->groupBy($criteria);

        $criterias = $this->map(function ($element, $key) use ($criteria) {
            return $criteria($element, $key);
        })->toArray();

        sort($criterias);
        $criterias = array_unique($criterias);

        foreach ($criterias as $key) {
            foreach ($groups[$key] as $element) {
                $sorted[] = $element;
            }
        }

        return $sorted;
    }
807488
protected function buildQueryBuilder(array $criteria, array $orderBy, $collection = false)
    {
        $queryBuilder = $collection ? $this->createQueryBuilderForCollection() : $this->createQueryBuilder();

        $this->applyCriteria($queryBuilder, $criteria);
        $this->applySorting($queryBuilder, $orderBy);

        return $queryBuilder;
    }
1287187
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $persister = $this->entityManager->getEntityPersister($this->className);

        return $persister->loadAll($criteria, $orderBy, $limit, $offset);
    }
160607
public function findByCriteria(Criteria $criteria, $order = null, $limit = null, $offset = 0)
    {
        $qb = $this->createCriteriaQueryBuilder($criteria, 'm');

        if ($order) {
            foreach ($order as $field => $dir) {
                $qb->orderBy("m.$field", $dir);
            }
        }
        if ($limit) {
            $qb->setMaxResults($limit);
        }
        if ($offset) {
            $qb->setFirstResult($offset);
        }

        return $qb->getQuery()->getResult();
    }
836099
public function findBy(array $criteria, ?array $sorting = null, $limit = null, $offset = null)
    {
        $queryBuilder = $this->getCollectionQueryBuilder();

        $this->applyCriteria($queryBuilder, $criteria);
        $this->applySorting($queryBuilder, $sorting);

        if (null !== $limit) {
            $queryBuilder->limit($limit);
        }

        if (null !== $offset) {
            $queryBuilder->skip($offset);
        }

        return $queryBuilder
            ->getQuery()
            ->getIterator()
        ;
    }
1139192
final public static function all($orderBy = ['createdAt' => 'DESC'], bool $withTrash = false)
    {
        $criteria = self::criteriaWithSoftDelete([], $withTrash);
        return static::getRepository()
            ->findBy($criteria, $orderBy);
    }
1342389
public function findOneBy(array $criteria, array $orderBy = null)
    {
        $persister = $this->entityManager->getEntityPersister($this->className);

        return $persister->load($criteria);
    }
1179061
public static function findByCriteria(array $criteria): ?Model\Collection
    {
        try {
            list($columns, $values, $options) = static::parseCriteria($criteria);
        } catch (NoTagsException $e) {
            return null;
        }

        if (\count($columns) < 1) {
            return static::findAll($options);
        }

        return static::findBy($columns, $values, $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;
    }
786450
protected function findWithCriteria(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $qb = $this->getLoadQuery();
        foreach ($criteria as $col => $val) {
            if (is_array($val)) {
                $qb->andWhere($this->getAlias() . ".$col IN(:$col)");
                $qb->setParameter(":$col", $val, Connection::PARAM_INT_ARRAY);
            } else {
                $qb->andWhere($this->getAlias() . ".$col = :$col");
                $qb->setParameter(":$col", $val);
            }
        }
        if ($orderBy) {
            $qb->orderBy($orderBy[0], $orderBy[1]);
        }
        if ($limit) {
            $qb->setMaxResults($limit);
        }
        if ($offset) {
            $qb->setFirstResult($offset);
        }

        return $qb;
    }