Skip to content

Commit

Permalink
Added conditional check to extract polymorphic relationship for hasMa…
Browse files Browse the repository at this point in the history
…ny (emberjs#5623)
  • Loading branch information
Parrryy committed Oct 4, 2018
1 parent 6252353 commit 46a3add
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions addon/serializers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,25 +686,25 @@ const JSONSerializer = Serializer.extend({
} else if (relationshipMeta.kind === 'hasMany') {
if (!isNone(relationshipHash)) {
data = new Array(relationshipHash.length);
for (let i = 0, l = relationshipHash.length; i < l; i++) {
let item = relationshipHash[i];
data[i] = this.extractRelationship(relationshipMeta.type, item);
if (relationshipMeta.options.polymorphic) {
for (let i = 0, l = relationshipHash.length; i < l; i++) {
let item = relationshipHash[i];
data[i] = this.extractPolymorphicRelationship(relationshipMeta.type, item, {
key,
resourceHash,
relationshipMeta,
});
}
} else {
for (let i = 0, l = relationshipHash.length; i < l; i++) {
let item = relationshipHash[i];
data[i] = this.extractRelationship(relationshipMeta.type, item);
}
}
}
}
relationship = { data };
}

let linkKey = this.keyForLink(key, relationshipMeta.kind);
if (resourceHash.links && resourceHash.links[linkKey] !== undefined) {
let related = resourceHash.links[linkKey];
relationship = relationship || {};
relationship.links = { related };
}

if (relationship) {
relationships[key] = relationship;
}
});

return relationships;
Expand Down

0 comments on commit 46a3add

Please sign in to comment.