[TYPO3-mvc] Wrong f:count
Christian Zenker
christian.zenker at 599media.de
Tue Apr 12 14:31:17 CEST 2011
On Tue, 12 Apr 2011 14:16:43 +0200, Fabian Fisahn
<fisahn at its-immaterial.com> wrote:
Hi Fabian.
This is a known bug - if I remember correctly it was already fixed in
trunk (I'm too lazy to look it up in forge right now ;) ).
This happens as the result object of a query is kind of "lazy loaded"
since the TYPO3 4.5 release. This allows the pagination widget to modify
the query before fetching the results for example. So before you actually
request an object from the query result object, it does not hold any
domain models.
The bug here is, that calling the count() method on the object will just
look how many objects have already been instanciated, but it does not
actually fetch the objects from the database.
> Is there a way to avoid the the foreach?
Without testing: $products->getFirst() should do the job. But be aware
that you won't be able to use the pagination viewHelper like mentioned
above after doing this.
Christian.
> Hello,
>
> I have a strange problem:
>
> Controller:
> $products = $this->productsRepository->findAll();
> $this->view->assign('items', $products);
>
> Fluid Template:
> <f:count subject="{items}" />
>
> The count result is incorrect
>
> If I insert a foreach in the controller, the result will be correct:
> $products = $this->productsRepository->findAll();
> foreach($products as $product){
> }
> $this->view->assign('items', $products);
>
> Strange, because the foreach does nothing.
>
> Is there a way to avoid the the foreach?
>
> Fabian
More information about the TYPO3-project-typo3v4mvc
mailing list