protected function getUncachedRelationCount($propertyName)
    {
        if ($this->$propertyName instanceof LazyObjectStorage) {
            $reflectionClass = new \ReflectionClass(LazyObjectStorage::class);
            $reflectionProperty = $reflectionClass->getProperty('fieldValue');
            $reflectionProperty->setAccessible(true);
            $count = (int)$reflectionProperty->getValue($this->$propertyName);
        } else {
            $count = $this->$propertyName->count();
        }

        return $count;
    }
protected function getUncachedRelationCount($propertyName)
    {
        if ($this->$propertyName instanceof LazyObjectStorage) {
            $reflectionClass = new \ReflectionClass(LazyObjectStorage::class);
            $reflectionProperty = $reflectionClass->getProperty('fieldValue');
            $reflectionProperty->setAccessible(true);
            $count = (int)$reflectionProperty->getValue($this->$propertyName);
        } else {
            $count = $this->$propertyName->count();
        }

        return $count;
    }
protected function getUncachedRelationCount ( $ propertyName ) { if ( $ this -> $ propertyName instanceof LazyObjectStorage ) { $ reflectionClass = new \ ReflectionClass ( LazyObjectStorage :: class ) ; $ reflectionProperty = $ reflectionClass -> getProperty ( 'fieldValue' ) ; $ reflectionProperty -> setAccessible ( true ) ; $ count = ( int ) $ reflectionProperty -> getValue ( $ this -> $ propertyName ) ; } else { $ count = $ this -> $ propertyName -> count ( ) ; } return $ count ; }
Retrieves the relation count for the given property.

This methods tries to avoid database accesses by using the relation counter cache if the relation is still
a LazyObjectStorage. Otherwise, the normal COUNT query will be performed as a fallback.

This method does not cache its results.

@param string $propertyName the name of the relation (plural, lower camelCase)

@return int

@throws \ReflectionException
Retrieves the relation count for the given property .