Skip to content

Commit

Permalink
Merge pull request #5667 from Parrryy/hasmany-polymorphic-extract
Browse files Browse the repository at this point in the history
Added check to extract polymorphic relationship for hasMany (#5623)
  • Loading branch information
runspired authored Oct 4, 2018
2 parents 0929425 + 550052e commit 4d593aa
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions addon/serializers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,20 @@ 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);
}
}
}
}
Expand Down

0 comments on commit 4d593aa

Please sign in to comment.