Add getExistsResult #7330

Open
opened 2026-01-22 15:50:02 +01:00 by admin · 0 comments
Owner

Originally created by @arkhamvm on GitHub (Feb 23, 2024).

Feature Request

Add getExistsResult method.

Q A
New Feature yes
RFC no
BC Break no

Summary

It would be nice to have method that checks that result of query is exists.

Now:

public function isExists(int $id): bool
{
  $queryBuilder = $this->entityRepository->createQueryBuilder('f');
  $exists       = $queryBuilder
      ->select('1')
      ->where('f.id = :id')
      ->setParameter('id', $id)
      ->getQuery()
      ->getOneOrNullResult()
  ;
  
  if (is_null($exists)) {
      return false;
  }
  
  return true;
}

After:

public function isExists(int $id): bool
{
  $queryBuilder = $this->entityRepository->createQueryBuilder('f');
  return $queryBuilder
      ->where('f.id = :id')
      ->setParameter('id', $id)
      ->getQuery()
      ->getExistsResult()
  ;
}
Originally created by @arkhamvm on GitHub (Feb 23, 2024). ### Feature Request Add `getExistsResult` method. | Q | A |------------ | ------ | New Feature | yes | RFC | no | BC Break | no #### Summary It would be nice to have method that checks that result of query is exists. Now: ```php public function isExists(int $id): bool { $queryBuilder = $this->entityRepository->createQueryBuilder('f'); $exists = $queryBuilder ->select('1') ->where('f.id = :id') ->setParameter('id', $id) ->getQuery() ->getOneOrNullResult() ; if (is_null($exists)) { return false; } return true; } ``` After: ```php public function isExists(int $id): bool { $queryBuilder = $this->entityRepository->createQueryBuilder('f'); return $queryBuilder ->where('f.id = :id') ->setParameter('id', $id) ->getQuery() ->getExistsResult() ; } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7330