Cached models have _original_relations populated #95

phil-lavin opened this Issue Sep 27, 2011 · 6 comments


None yet

3 participants


If you load a model and add something to a relation and then re-load that model, it is loaded from cache. However, the data that you have put into the relation is considered 'original' and, as such, if you try to save that model it doesn't save the relation.

This has been tested by turning $obj to false after it is loaded from cache to force it to be reloaded from the DB.


I have to undo this fix, it was wrong.

@jschreuder jschreuder reopened this Oct 25, 2011
@jschreuder jschreuder added a commit that referenced this issue Oct 25, 2011
@jschreuder jschreuder Undoing fix to #95 and reopening it.
The fix doesn't work as hydrate() is called for each row separately, thus the second row doesn't know the first one updated it. The only way to solve this is to keep track per model instance if relations were updated or not.

As said in the above commit's description there needs to be some way to keep track per model instance which relations are being updated and won't overwrite new changes. With that info it should be possible to mostly put back what I just undid.

Fuel member


Trying to get rid of these old open issues.

Would it be save to say that retrieved relations should be hydrated if the model object came NOT from cache, OR if the relation on the object wasn't fetched before? i.e. don't touch the relation if the model object was retrieved from cache, and it has already fetched the relation?

Fuel member

To be more precise, it's save to hydrate the related data if the objects $_original_relations property DOES NOT have an entry for the relation (which means it wasn't fetched on the query that created the cached item)?


"phil-lavin opened this issue 2 years ago"

Cut me some slack! :P

From what I remember, it is to do with when a relation becomes 'original'. It should only do it when the object is saved and not when it's put into/loaded from cache.

Fuel member

Problem is deeper. As objects are used by reference, once you retrieve an object from the ORM cache and you start modifying it, it will modify all other variables pointing to the same cache object.

Which means that even if you only process relations not fetched on the query that created the cached object, after processing all other variables having the same object reference will be updated too.

This sounds like unwanted behavoir, from what I understand you really want a new object, not a modified cached one. You don't want the cached one to be touched.

@WanWizard WanWizard closed this in bf5d7c6 Apr 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment