Skip to content

Commit

Permalink
Merge pull request #4451 from lkhaas/remove-ds-serialize-ids-and-types
Browse files Browse the repository at this point in the history
[CLEANUP beta] Remove feature flag for ds-serialize-ids-and-types (shipped in 2.6) #4416
  • Loading branch information
bmac authored Jun 27, 2016
2 parents d733b10 + e51a0e1 commit afaddf5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 62 deletions.
24 changes: 0 additions & 24 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,6 @@ entry in `config/features.json`.
Enables `pushPayload` to return the model(s) that are created or
updated via the internal `store.push`.

- `ds-serialize-ids-and-types` [#3848](https://github.com/emberjs/data/pull/3848)

Enables a new `ids-and-type` strategy (in addition to the already existing `ids` and `records`) for
serializing has many relationships using the `DS.EmbeddedRecordsMixin` that will include both
`id` and `type` of each model as an object.

For instance, if a use has many pets, which is a polymorphic relationship, the generated payload would be:

```js
{
"user": {
"id": "1"
"name": "Bertin Osborne",
"pets": [
{ "id": "1", "type": "Cat" },
{ "id": "2", "type": "Parrot"}
]
}
}
```

This is particularly useful for polymorphic relationships not backed by STI when just including the id
of the records is not enough.

- `ds-extended-errors` [#3586](https://github.com/emberjs/data/pull/3586) [#4287](https://github.com/emberjs/data/pull/4287)

Enables `extend` method on errors. It means you can extend from `DS.AdapterError`.
Expand Down
9 changes: 2 additions & 7 deletions addon/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Ember from 'ember';
import { warn } from "ember-data/-private/debug";
import isEnabled from 'ember-data/-private/features';

var get = Ember.get;
var set = Ember.set;
Expand Down Expand Up @@ -365,8 +364,6 @@ export default Ember.Mixin.create({
}
```
Note that the `ids-and-types` strategy is still behind the `ds-serialize-ids-and-types` feature flag.
@method serializeHasMany
@param {DS.Snapshot} snapshot
@param {Object} json
Expand All @@ -385,10 +382,8 @@ export default Ember.Mixin.create({
} else if (this.hasSerializeRecordsOption(attr)) {
this._serializeEmbeddedHasMany(snapshot, json, relationship);
} else {
if (isEnabled("ds-serialize-ids-and-types")) {
if (this.hasSerializeIdsAndTypesOption(attr)) {
this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship);
}
if (this.hasSerializeIdsAndTypesOption(attr)) {
this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship);
}
}
},
Expand Down
1 change: 0 additions & 1 deletion config/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"ds-boolean-transform-allow-null": null,
"ds-improved-ajax": null,
"ds-pushpayload-return": null,
"ds-serialize-ids-and-types": true,
"ds-extended-errors": null,
"ds-links-in-record-array": null,
"ds-overhaul-references": null,
Expand Down
57 changes: 27 additions & 30 deletions tests/integration/serializers/embedded-records-mixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import testInDebug from 'dummy/tests/helpers/test-in-debug';
import {module, test} from 'qunit';

import DS from 'ember-data';
import isEnabled from 'ember-data/-private/features';

var get = Ember.get;
var HomePlanet, SuperVillain, CommanderVillain, NormalMinion, EvilMinion, YellowMinion, RedMinion, SecretLab, SecretWeapon, BatCave, Comment,
Expand Down Expand Up @@ -1074,38 +1073,36 @@ test("serialize with embedded objects (hasMany relationships, including related
});
});

if (isEnabled("ds-serialize-ids-and-types")) {
test("serialize has many relationship using the `ids-and-types` strategy", function(assert) {
run(function() {
yellowMinion = env.store.createRecord('yellow-minion', { id: 1, name: "Yellowy" });
redMinion = env.store.createRecord('red-minion', { id: 1, name: "Reddy" });
commanderVillain = env.store.createRecord('commander-villain', { id: 1, name: "Jeff", minions: [yellowMinion, redMinion] });
});
test("serialize has many relationship using the `ids-and-types` strategy", function(assert) {
run(function() {
yellowMinion = env.store.createRecord('yellow-minion', { id: 1, name: "Yellowy" });
redMinion = env.store.createRecord('red-minion', { id: 1, name: "Reddy" });
commanderVillain = env.store.createRecord('commander-villain', { id: 1, name: "Jeff", minions: [yellowMinion, redMinion] });
});

env.registry.register('serializer:commander-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
minions: { serialize: 'ids-and-types' }
}
}));
var serializer, json;
run(function() {
serializer = env.container.lookup("serializer:commander-villain");
var snapshot = commanderVillain._createSnapshot();
json = serializer.serialize(snapshot);
});
env.registry.register('serializer:commander-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
minions: { serialize: 'ids-and-types' }
}
}));
var serializer, json;
run(function() {
serializer = env.container.lookup("serializer:commander-villain");
var snapshot = commanderVillain._createSnapshot();
json = serializer.serialize(snapshot);
});

assert.deepEqual(json, {
name: 'Jeff',
minions: [{
id: '1',
type: 'yellow-minion'
}, {
id: '1',
type: 'red-minion'
}]
});
assert.deepEqual(json, {
name: 'Jeff',
minions: [{
id: '1',
type: 'yellow-minion'
}, {
id: '1',
type: 'red-minion'
}]
});
}
});

test("normalizeResponse with embedded object (belongsTo relationship)", function(assert) {
env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
Expand Down

0 comments on commit afaddf5

Please sign in to comment.