You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Models that fail a save to the DB still save to the cache #78
Hi, I'm not sure if this is by design or not, but I noticed if a model fails validation during save, it is still saved to the cache. I'm using postgres.
Project.get(1,function(err,project){project.project_status='foo';project.save(function(err){//This will print a validation errorconsole.log(err);});});
Later, retrieving the model will print the invalid value.
Project.get(1,function(err,project){//This will print 'foo'console.log(project.project_status);});
What do you think? If you use the last git version your problem should be solved. Still, for people wanting the old behaviour, it's just a setting away.
varorm=require("orm");orm.settings.set("instance.cacheSaveCheck",false);// true by default
Looks good to me. Let me see if I understand. You enabled cacheSaveCheck to be true by default, and now saving to cache will check to see if it was saved to the cache first?
I created cacheSaveCheck that if enabled (default) will not return an instance from cache if it's not saved. So if you fetch A, change it, and then fetch again, the cache will see that what it has is not saved and so will fetch it again.
Activity
dresende commentedon Mar 15, 2013
This is somewhat the expected behaviour, I'm not sure the best strategy to avoid this. If you do this on the second
Person.get:Perhaps I can force the Singleton object to fetch from database when cached instance is not saved. What do you think?
This made me think that an
Instance.revert()might also come in handy.Changes Singleton to avoid cache if save_check option is enabled and …
Adds default setting instance.cacheSaveCheck = true (#78)
Changes Model to pass instance.cacheSaveCheck setting to Singleton (#78)
Fixes test-get-cache test for new behaviour (#78)
Adds test for cached Model.get() with instance.cacheSaveCheck disabled (
dresende commentedon Mar 15, 2013
What do you think? If you use the last git version your problem should be solved. Still, for people wanting the old behaviour, it's just a setting away.
robseward commentedon Mar 16, 2013
Looks good to me. Let me see if I understand. You enabled cacheSaveCheck to be true by default, and now saving to cache will check to see if it was saved to the cache first?
dresende commentedon Mar 17, 2013
I created cacheSaveCheck that if enabled (default) will not return an instance from cache if it's not saved. So if you fetch A, change it, and then fetch again, the cache will see that what it has is not saved and so will fetch it again.
dresende commentedon Mar 19, 2013
I'll assume this now behaves as you expected. If not please reopen and explain :)