[TYPO3-mvc] Possible bug: LazyObjectStorage->toArray should initialize the objectStorage first?
Franz Koch
typo3.RemoveForMessage at elements-net.de
Sat May 29 01:15:32 CEST 2010
Hey,
> I'm not sure if this is directly related to your problem, but inside the
> domain models it's always done like this for lazy loading:
>
> public function getCategories() {
> if($this->categories instanceof Tx_Extbase_Persistence_LazyLoadingProxy) {
> $this->categories->_loadRealInstance();
> }
>
> return clone $this->categories;
> }
... maybe it's also possible to get rid of this
> manual loading of the 'real' objects and let Extbase load it when they
> are accessed?!
That's actually the case by default. You don't have to load the
"realInstance" by your own. In general you can instantly work with the
LazyObjectStorage as well as the LazyLoadingProxy (never had any issues
so far).
Example:
----------- model class ----------------
/**
* Topics
* @var
Tx_Extbase_Persistence_ObjectStorage<Tx_EbExhibition_Domain_Model_Topic>
* @lazy
*/
protected $topics;
/** proper doc comment */
public function getTopics() {
return $this->topics;
}
----------------------------------------
----------- usecase --------------------
// will return the count of the ObjectStorage even without fetching the
objects
echo $model->getTopics()->count();
// will load all objects automatically and return the current
$current = $model->getTopics()->current();
----------------------------------------
So in general extbase is doing the magic transparently in the background
and you don't have to care if you're working with the real object or a
lazy one. That's why I asked if the current behavior of ->toArray is
intended or a bug.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list