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

relationships in "new" state should not be pushed to LS #136

Open
Leooo opened this issue Nov 2, 2015 · 0 comments
Open

relationships in "new" state should not be pushed to LS #136

Leooo opened this issue Nov 2, 2015 · 0 comments

Comments

@Leooo
Copy link

Leooo commented Nov 2, 2015

From https://github.com/emberjs/data/blob/v2.1.0/packages/ember-data/lib/system/relationships/state/relationship.js#: setHasData:

/*All relationships for a newly created ('store.createRecord()') are
  considered known ('hasData === true').
*/

=> serializeHasMany:

serializeHasMany: function(snapshot, json, relationship) {
  //..
  //json[payloadKey] = snapshot.hasMany(key, { ids: true });
  var onlyNotNew=snapshot.hasMany(key);
  if (onlyNotNew) {
    onlyNotNew=onlyNotNew
      .filter(function(rel){return !rel.get("isNew");})
      .map(function(rel){return rel.id;});
  }
  json[payloadKey] = onlyNotNew || [];
  //..
}

serializeBelongsTo:

      serializeBelongsTo: function(snapshot, json, relationship) {
        var key = relationship.key;
          var onlyNotNew=snapshot.belongsTo(key);
          if (onlyNotNew) {
            if (!onlyNotNew.get("isNew")) {
              onlyNotNew=onlyNotNew.id;
            }
            else {
              onlyNotNew=null;
            }
          }
          var belongsToId = onlyNotNew;
          var payloadKey = this._getMappedKey(key);
          if (payloadKey === key && this.keyForRelationship) {
            payloadKey = this.keyForRelationship(key, "belongsTo");
          }
          if (Ember.isNone(belongsToId)) {
            json[payloadKey] = null;
          } else {
            json[payloadKey] = belongsToId;
          }
          if (relationship.options.polymorphic) {
            this.serializePolymorphicType(snapshot, json, relationship);
          }
        }
      },
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

1 participant