Skip to content

Commit

Permalink
[BUGFIX release] JSONSerializer pass through payload.included
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Stirrat committed Jul 15, 2015
1 parent ab1f538 commit 3a2a0d9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Master

- [#3550](https://github.com/emberjs/data/pull/3550) JSONSerializer now works with EmbeddedRecordsMixin by respecting the `included` property in normalizeResponse [@tstirrat](https://github.com/tstirrat)

### Release 1.13.5 (July 8, 2015)

- [#3437](https://github.com/emberjs/data/pull/3437) Deprecate normalizePayload and normalizeHash [@wecc](https://github.com/wecc)
Expand Down Expand Up @@ -122,9 +124,9 @@

##### Store Service moved to an Instance Initializer

In order to fix deprecations warning induced by Ember 1.12, the store service
is now injected as an instanceInitializer. As a consequence, if you had initializers
depending on the store, you should move them to an instance initializer as well,
In order to fix deprecations warning induced by Ember 1.12, the store service
is now injected as an instanceInitializer. As a consequence, if you had initializers
depending on the store, you should move them to an instance initializer as well,
and mark it as after: 'ember-data'.

- Removed support for DS.FixtureAdapter. You can use it as an addon, or
Expand Down
6 changes: 4 additions & 2 deletions packages/ember-data/lib/serializers/json-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,13 @@ var JSONSerializer = Serializer.extend({
}

if (isSingle) {
let { data } = this.normalize(primaryModelClass, payload);
let { data, included } = this.normalize(primaryModelClass, payload);
documentHash.data = data;
documentHash.included = included;
} else {
documentHash.data = payload.map((item) => {
let { data } = this.normalize(primaryModelClass, item);
let { data, included } = this.normalize(primaryModelClass, item);
documentHash.included.push(...included);
return data;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,29 @@ test('normalizeResponse should extract meta using extractMeta', function() {

deepEqual(post.meta.authors, ['Tomster', 'Tomhuda']);
});

test('normalizeResponse respects `included` items', function() {
env.registry.register("serializer:post", DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
comments: { embedded: 'always' }
}
}));

var jsonHash = {
id: "1",
title: "Rails is omakase",
comments: [
{ id: "1", title: "comment 1" },
{ id: "2", title: "comment 2" }
]
};

var post = env.store.serializerFor("post").normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord');

deepEqual(post.included, {
data: [
{ id: "1", type: "comment", attributes: { title: "comment 1" } },
{ id: "2", type: "comment", attributes: { title: "comment 2" } }
]
});
});

0 comments on commit 3a2a0d9

Please sign in to comment.