Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecation and fallback for keyForAttribute when keyForPolymo… #5291

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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