kurko / ember-sync

MIT License
282 stars 28 forks source link

[WIP] online/offline syncing loses hasMany relationship #17

Closed tute closed 9 years ago

tute commented 10 years ago

Related issue: https://github.com/kurko/ember-sync/issues/15#issuecomment-48251695.

Can't get to meaningful error messages yet, it stalls with:

Error: Assertion Failed: You looked up the 'cartItems' relationship on '<(subclass of DS.Model):ember311:1>' but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (DS.hasMany({ async: true }))

tute commented 10 years ago

Also, adding that tests make others flap. Tests run interleaved?

This test is almost a clone of the previous one, should we remove the first one?

will-hart commented 10 years ago

This issue is also giving me a hard time :)

Applying your commented patch above seemed to do the trick for the relationships but causes exceptions in other instances. For example:

value = new Date();
typeof(value);  //object
value.toArray(); // TypeError: undefined is not a function

According to some research checking for isArray is a bit ugly. I've tried changing your code to:

var key, value, _ref;
_ref = record._data;
for (key in _ref) {
    value = _ref[key];
    if (typeof value === 'object' && (value instanceof Array)) { // <-- this line changed
        serialized[key] = value.toArray();
    }
}

This fixes the TypeError, however the relationships still aren't persisted (tested with localForage). Any further thoughts on this issue?

kurko commented 9 years ago

@will-hart @tute I fixed this on ca9797661e253842389d04056242aff3ea22eda9 :grin: