Skip to content

Commit

Permalink
Merge pull request #5291 from bmac/key-for-polymorphic-type
Browse files Browse the repository at this point in the history
Remove deprecation and fallback for keyForAttribute when keyForPolymo…
  • Loading branch information
rwjblue authored Dec 19, 2017
2 parents 79ee129 + baae243 commit 4ce9a75
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
18 changes: 0 additions & 18 deletions addon/serializers/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,24 +762,6 @@ const RESTSerializer = JSONSerializer.extend({
let typeKey = this.keyForPolymorphicType(key, relationship.type, 'serialize');
let belongsTo = snapshot.belongsTo(key);

// old way of getting the key for the polymorphic type
key = this.keyForAttribute ? this.keyForAttribute(key, "serialize") : key;
key = `${key}Type`;

// The old way of serializing the type of a polymorphic record used
// `keyForAttribute`, which is not correct. The next code checks if the old
// way is used and if it differs from the new way of using
// `keyForPolymorphicType`. If this is the case, a deprecation warning is
// logged and the old way is restored (so nothing breaks).
if (key !== typeKey && this.keyForPolymorphicType === RESTSerializer.prototype.keyForPolymorphicType) {
deprecate("The key to serialize the type of a polymorphic record is created via keyForAttribute which has been deprecated. Use the keyForPolymorphicType hook instead.", false, {
id: 'ds.rest-serializer.deprecated-key-for-polymorphic-type',
until: '3.0.0'
});

typeKey = key;
}

if (isNone(belongsTo)) {
json[typeKey] = null;
} else {
Expand Down
21 changes: 0 additions & 21 deletions tests/integration/serializers/rest-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,27 +573,6 @@ test('serializeBelongsTo with async polymorphic', function(assert) {
assert.deepEqual(json, expected, 'returned JSON is correct');
});

testInDebug('serializeBelongsTo logs deprecation when old behavior for getting polymorphic type key is used', function(assert) {
var evilMinion, doomsdayDevice;
var json = {};
var expected = { evilMinion: '1', myCustomKeyType: 'evilMinion' };

env.restSerializer.keyForAttribute = function() {
return 'myCustomKey';
};

run(function() {
evilMinion = env.store.createRecord('evil-minion', { id: 1, name: 'Tomster' });
doomsdayDevice = env.store.createRecord('doomsday-device', { id: 2, name: 'Yehuda', evilMinion: evilMinion });
});

assert.expectDeprecation(function() {
env.restSerializer.serializeBelongsTo(doomsdayDevice._createSnapshot(), json, { key: 'evilMinion', options: { polymorphic: true, async: true } });
}, "The key to serialize the type of a polymorphic record is created via keyForAttribute which has been deprecated. Use the keyForPolymorphicType hook instead.");

assert.deepEqual(json, expected, 'returned JSON is correct');
});

test('keyForPolymorphicType can be used to overwrite how the type of a polymorphic record is serialized', function(assert) {
var evilMinion, doomsdayDevice;
var json = {};
Expand Down

0 comments on commit 4ce9a75

Please sign in to comment.