-2

Is it possible to apply criteria >= condition in Doctrine findBy. I have a query like this:

select * from source where id >= 10

I am looking to apply in following way which will return with reference to Object source.

$this->entityManager->getRepository(Source::class)->findBy(['id' ])

I can use createQueryBuilder but it returns me array result. I need result in same format as above:

$qb = $this->createQueryBuilder('s')
                    ->andWhere('s.id >= :id')
                    ->setParameter('id', 10);

Expected Result:

0 => App\Entity\Source {#845
    -id: 10

Can anybody help me?

Thanks in advance.

user1687891
  • 794
  • 2
  • 14
  • 30

1 Answers1

1

You could use the repository's matching method.

$criteria = Criteria::create()
            ->andWhere(Criteria::expr()->gte('id', 10));

$repository->matching($criteria);

Be aware that doctrine can not always hydrate your database data on Entities, when using custom queries. The result is that it only returns array data.

Leroy
  • 1,600
  • 13
  • 23