From 3e26330c534b1784f023fd3b7bc4ef72cca3f422 Mon Sep 17 00:00:00 2001 From: Oliver Tischlinger Date: Wed, 23 Sep 2015 17:34:11 +0200 Subject: [PATCH] check if collection is empty without loading it Actually isEmpty() is always loading the collection in LazyCriteriaCollection. A lazy version should use the existing functionality of count() to check if there are no elements if the collection is not initialized. --- lib/Doctrine/ORM/LazyCriteriaCollection.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Doctrine/ORM/LazyCriteriaCollection.php b/lib/Doctrine/ORM/LazyCriteriaCollection.php index 28e2709ac..876341c72 100644 --- a/lib/Doctrine/ORM/LazyCriteriaCollection.php +++ b/lib/Doctrine/ORM/LazyCriteriaCollection.php @@ -82,6 +82,20 @@ class LazyCriteriaCollection extends AbstractLazyCollection implements Selectabl return $this->count = $this->entityPersister->count($this->criteria); } + /** + * check if collection is empty without loading it + * + * @return boolean TRUE if the collection is empty, FALSE otherwise. + */ + public function isEmpty() + { + if ($this->isInitialized()) { + return $this->collection->isEmpty(); + } + + return $this->count() == 0; + } + /** * Do an optimized search of an element *