Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set(id) {
const normalizedId = coerceId(id);
if (normalizedId !== null) {
this._internalModel.setId(normalizedId);
}
},
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 {
extractId(modelClass, resourceHash) {
let primaryKey = get(this, 'primaryKey');
let id = resourceHash[primaryKey];
return coerceId(id);
},
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 };
},
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 };
},