[TYPO3-mvc] Using repository inside an entity
Franz Koch
typo3.RemoveForMessage at elements-net.de
Sun Apr 25 15:31:46 CEST 2010
Hey,
> /**
> * Returns all items for sale in this category
> *
> * @return
> Tx_Extbase_Persistence_ObjectStorage<Tx_Dabmarket_Domain_Model_Item>
> */
> public function getItemsForSale() {
> $this->itemRepository =
> t3lib_div::makeInstance('Tx_Dabmarket_Domain_Repository_ItemRepository');
> return $this->itemRepository->findForSaleByCategory($this);
> }
I see one big problem with this: repeated calls. Assume a FLUID template
like this:
<f:if condition="{f:count(subject: myObject.itemsForSale)}">
<f:for each="{myObject.itemsForSale}" as="item">do something</f:for>
</f:if>
In such a situation every use of the property "itemsForSale" will
trigger your method and thus fetch the items over and over again from
the repository, so you should consider making use of some internal "cache".
A better approach might be to move all the logic with the cache etc to a
dedicated service and only call this service from inside your model.
$this->myService->getItemsForSaleByProduct($this);
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list