[BUGFIX] Use count on storage after initialization of LazyObjectStorage 43/27443/2
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Wed, 5 Feb 2014 12:42:32 +0000 (13:42 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 21 Feb 2014 19:41:32 +0000 (20:41 +0100)
The count in LazyObjectStorage for relation type HAS_MANY has
to use the count on storage items after initialization. Otherwise
the wrong count is returned for a not persisted storage.

Resolves: #54724
Releases: 6.2, 6.1, 6.0
Change-Id: I817ce86dde11b175e6a5765a8f6518770ba75f28
Reviewed-on: https://review.typo3.org/27443
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/extbase/Classes/Persistence/Generic/LazyObjectStorage.php

index 3661ddb..c22b546 100644 (file)
@@ -175,7 +175,7 @@ class LazyObjectStorage extends \TYPO3\CMS\Extbase\Persistence\ObjectStorage imp
        public function count() {
                $columnMap = $this->dataMapper->getDataMap(get_class($this->parentObject))->getColumnMap($this->propertyName);
                $numberOfElements = NULL;
-               if ($columnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
+               if (!$this->isInitialized && $columnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
                        $numberOfElements = $this->dataMapper->countRelated($this->parentObject, $this->propertyName, $this->fieldValue);
                } else {
                        $this->initialize();
@@ -318,4 +318,4 @@ class LazyObjectStorage extends \TYPO3\CMS\Extbase\Persistence\ObjectStorage imp
        }
 }
 
-?>
\ No newline at end of file
+?>