How to use the @ember-data/store/-private.coerceId function in @ember-data/store

To help you get started, we’ve selected a few @ember-data/store examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emberjs / data / packages / model / addon / -private / model.js View on Github external
set(id) {
    const normalizedId = coerceId(id);

    if (normalizedId !== null) {
      this._internalModel.setId(normalizedId);
    }
  },
github emberjs / data / packages / serializer / addon / rest.js View on Github external
data.forEach(resource => {
          /*
            Figures out if this is the primary record or not.

            It's either:

            1. The record with the same ID as the original request
            2. If it's a newly created record without an ID, the first record
               in the array
           */
          let isUpdatedRecord = isPrimary && coerceId(resource.id) === id;
          let isFirstCreatedRecord = isPrimary && !id && !documentHash.data;

          if (isFirstCreatedRecord || isUpdatedRecord) {
            documentHash.data = resource;
          } else {
            documentHash.included.push(resource);
          }
        });
      } else {
github emberjs / data / packages / serializer / addon / json.js View on Github external
extractId(modelClass, resourceHash) {
    let primaryKey = get(this, 'primaryKey');
    let id = resourceHash[primaryKey];
    return coerceId(id);
  },
github emberjs / data / packages / serializer / addon / json.js View on Github external
extractRelationship(relationshipModelName, relationshipHash) {
    if (isNone(relationshipHash)) {
      return null;
    }
    /*
      When `relationshipHash` is an object it usually means that the relationship
      is polymorphic. It could however also be embedded resources that the
      EmbeddedRecordsMixin has be able to process.
    */
    if (typeOf(relationshipHash) === 'object') {
      if (relationshipHash.id) {
        relationshipHash.id = coerceId(relationshipHash.id);
      }

      let modelClass = this.store.modelFor(relationshipModelName);
      if (relationshipHash.type && !modelHasAttributeOrRelationshipNamedType(modelClass)) {
        relationshipHash.type = this.modelNameFromPayloadKey(relationshipHash.type);
      }

      return relationshipHash;
    }
    return { id: coerceId(relationshipHash), type: relationshipModelName };
  },
github emberjs / data / packages / serializer / addon / json.js View on Github external
is polymorphic. It could however also be embedded resources that the
      EmbeddedRecordsMixin has be able to process.
    */
    if (typeOf(relationshipHash) === 'object') {
      if (relationshipHash.id) {
        relationshipHash.id = coerceId(relationshipHash.id);
      }

      let modelClass = this.store.modelFor(relationshipModelName);
      if (relationshipHash.type && !modelHasAttributeOrRelationshipNamedType(modelClass)) {
        relationshipHash.type = this.modelNameFromPayloadKey(relationshipHash.type);
      }

      return relationshipHash;
    }
    return { id: coerceId(relationshipHash), type: relationshipModelName };
  },