Skip to content
Browse files

Consider relationship for embedded hasMany records.

When serializing a relationship, the previous algorithm serialized all
records in _all_ has-many relationships, not just all records for the
specified relationship.
  • Loading branch information...
1 parent 54927ae commit adee9f4541562d9c909f1a9c6215e6b390d50f7e @yipdw yipdw committed
Showing with 12 additions and 4 deletions.
  1. +12 −4 packages/ember-data/lib/serializers/json_serializer.js
View
16 packages/ember-data/lib/serializers/json_serializer.js
@@ -110,11 +110,19 @@ DS.JSONSerializer = DS.Serializer.extend({
},
addHasMany: function(hash, record, key, relationship) {
- var array = [];
+ var type = record.constructor,
+ name = relationship.key,
+ array = [],
+ self = this,
+ target;
- this.eachEmbeddedHasManyRecord(record, function(embeddedRecord) {
- array.push(this.serialize(embeddedRecord, { includeId: true }));
- }, this);
+ if (this.embeddedType(type, name)) {
+ if (target = get(record, name)) {
+ target.forEach(function (record) {
+ array.push(self.serialize(record, { includeId: true }));
+ });
+ }
+ }
hash[key] = array;
},

0 comments on commit adee9f4

Please sign in to comment.
Something went wrong with that request. Please try again.