[TYPO3-mvc] Assigning lazy loaded objects to objects

Thomas "Thasmo" Deinhamer thasmo at gmail.com
Wed Jun 2 17:15:54 CEST 2010


Am 02.06.2010 16:52, schrieb roberto blanko:
> Hello again,
>
> my scenario:
>
> $germany = new Tx_MyExt_Domain_Model_Nation();
> $germany->setPresident($oldGermany->getPresident());
> $this->nationRepository->add($germany);
>
> The attribute $president is lazyly loaded.
>
> The problem: The relation between the president and $germany is not written
> to the database due to the fact, that $oldGermany->getPresident() does not
> return an object of class Tx_MyExt_Domain_Model_President but of
> Tx_Extbase_Persistence_LazyLoadingProxy. I guess the repository can not
> handle this. I could use $oldGermany->getPresident()->_loadRealInstance()
> instead. This works but this doesn't seem right or very future-proof
> especially since that method is commented with "@return object The instance
> (hopefully) returned". Hopefully is not a good word in terms of IT.
>
> Any ideas how to solve my problem?
>
> Regards
> Roberto

I think this is working as intended,
you need to do it this way:

$germany = new Tx_MyExt_Domain_Model_Nation();
$president = $oldGermany->getPresident(); // should maybe return a clone
$president->setNation($germany);
$germany->setPresident($president);
$this->nationRepository->add($germany);

Althouh I'm not sure, but give it a try.

Thomas


More information about the TYPO3-project-typo3v4mvc mailing list