[TYPO3-mvc] Auto-Updating related objects
Franz Koch
typo3.RemoveForMessage at elements-net.de
Tue Jul 12 12:17:26 CEST 2011
Hi,
> I'm currently working on an extension that fetches most of its data from
> a REST API. The problem is, I do not want to save all data (eg.: by
> running a scheduler task every day), because that would create thousands
> of records that will never be used. For the aggregate roots that is not
> a problem. If a findOneByName does not return a result, ask the API. The
> problem are related objects.
>
> eg.:
> $account = $accountRepository->findOneByName($name); // Already exists
> $roles = $account->getRoles(); // Related role objects can change over time
>
> foreach($roles as $role) $role->getName(); // ....
...
> So before I start hacking around, any ideas?
how about moving part of that logic into your domain models?
public function getRoles() {
if (!$this->roles->count()) {
$objectManager =
t3lib_div::makeInstance('Tx_Extbase_Persistence_ObjectManager');
$service =
$objectManager->get('Tx_YourExt_Domain_Service_AccountService');
return $service->getRolesByAccount($this);
}
return clone $this->roles;
}
Once DI for domain models is fully implemented (patches are currently
reviewed on gerrit) you could also use DI to inject your
service/repository or whatever you like to trigger to get your roles
from the REST api. But please note that when using DI to f.e. inject the
objectManager/Service/Repository you might no longer be able to debug
the domain models with current debug methods due to the nested relations
on those objects (resulting in a white page/server error).
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list