[TYPO3-mvc] Possible misunderstanding of repository / variable scope?

Andreas Kiessling andreas.kiessling at web.de
Thu Jun 20 21:51:22 CEST 2013


Hi,

Am 20.06.13 19:40, schrieb Jan Kornblum:
> Hi Frans,
> 
>> Probely because all objects are linked (references and not copies).
>>
>> So basicly the first set of items is the same as the second.
>> nl1.php.net/references
> 
> Thanks!
> 
> But what can i do instead to get 2 independent sets of objects (just
> like they are stored in the database and not modified)? What i want to
> have is:
> 
> $a=$repo->findAll()
> ... modify all items in $a, but do not persist them
> 
> $b=$repo->findAll()
> ... get the items as they are originally stored in the database
> 
> 

Your problem is actually an important feature of extbase and the object
lifecycle.
When extbase fetches the records, it looks at the uid and will return an
instance from a cache, if this record was already in a previous query.

When the persistence manager saves the models back to the db but there
are multiple instances of ONE record: how should it know, which one
"wins" and thus will be persisted last?

If you don't need the model/query result, you could use the result as an
array http://forge.typo3.org/projects/typo3v4-mvc/wiki/QueryResult
or you can clone the objects before modifying them. But beware of any
attached records: they will reference the same objects, if you don't
clone them too. Is there no other way to achieve what you want?

HTH,
Andreas


More information about the TYPO3-project-typo3v4mvc mailing list