Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't override the offlineStore records with empty records created on the online store due to id-only relationships fetched #37

Open
Leooo opened this issue Apr 30, 2015 · 1 comment

Comments

@Leooo
Copy link

Leooo commented Apr 30, 2015

a post and many comments exist and are stored offline.

When refreshing the page, the offline models are created, and no online models exist.

If refreshing only the post from the server (and returning the list of ids for the comments), the online store will create empty records for the comments, as it is not aware of any existing comments yet. These empty comments are then pushed to the offline server, overriding the old, correct, comments.

A solution: don't push to collection associations when the corresponding models are empty:

    Record.reopen({
      _serializeAssociations: function() {
        var serializedCollection = [],
            _this = this,
            snapshot = this._snapshot();
        snapshot.eachRelationship(function(name, relationship) {
          var hasManyRecords = null;

          var pushToCollection = function(snapshot) {
             if (typeof(snapshot)==='undefined') {return true;}
             if (snapshot.get('isEmpty')) {
              //added: don't replace offline record..
              return true;
            }
           //(..)
        });
      },
    });
@Leooo Leooo changed the title Don't override the offlineStore records with empty records which were created on id-only relationships Don't override the offlineStore records with empty records created on the online store due to id-only relationships fetched Apr 30, 2015
@kurko
Copy link
Owner

kurko commented Jun 12, 2015

Any chance you could open a PR with this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants