cayasso/oomvc — Issue #20: ** I THINK I FOUND (and fixed) THE SYNC BUG!!!
Author: noctivityinc
Created: 2011-10-30 03:25:04+00:00
State: open

I cracked it!

So the sync thing with update was happening AGAIN. It was driving me nuts. I traced it all the way down to the core and found out what is happening.

Basically when you call _update on an instance in a collection it is using the "data" object for that instance. The PROBLEM is that the data object is OLD! It's the data from the LAST TIME that that instance was synced! So if you have updated any of the values, which is why you are calling update() of course, then its using OLD values.

All I had to do was replace "data" with the contents of "this" when update() was called on a collection instance and it WORKED PERFECTLY!

Here is the updated _update() method that I am using that appears to work. I might be wrong and this could break something else but so far it's been working and always uses the latest values since Im replacing data with this.

http://pastie.textmate.org/private/ca1uus8umenmaiike2exmg

The question is this - where ELSE do you need to make this change? I believe that you also need to add "data = this" in the _save() method for a collection and possibly elsewhere. I didn't want to touch it until you looked it over.

Anyway, with this fix I can now persist and save changes to the db. Please take a look and let me know if what I'm saying now makes sense and if this is, in fact, the right fix for this problem. If so, please update your source and whatever other methods need updating with this fix, bump the version and repost.

I can now sleep!

Thx.

J