Skip to content

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

@Leooo

Description

@Leooo

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;
            }
           //(..)
        });
      },
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions