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

Jan Kornblum jan.kornblum at gmx.de
Fri Jun 21 09:45:15 CEST 2013


Hi Andreas,

>> 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.

Thank you for making this clear to me! This is certainly a great 
feature i havent read about so clearly anywhere. Maybe i should read 
the extbase book at least a second time...

A last question: Does it mean when having several findAll()'s on a 
single page request, the second+ findAll() doesn't fetch the DB at all 
but just gets all instances from cache, or does it fetch the DB + 
"join" the result with the instances in cache?

> 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

So $query->execute()->toArray() really gets all items from the DB and 
doesn't compare / join anything with the cache? It that right?

> 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?

Hmm, maybe i've got an idea: Instead of using one not persistable 
property in my model (currently used for 2 different logical things), i 
could better use two different not persistable properties. That would 
avoid interfering each other and might be a cleaner solution...

Kind regards, Jan




More information about the TYPO3-project-typo3v4mvc mailing list