<commit_before>---
title: Deprecations for Ember Data v2.x
alias: guides/deprecations/
layout: deprecations
---

## Deprecations Added in Ember Data 2.x

### Deprecations Added in Ember Data 2.3

#### Non-primitive defaultValue for Model Attributes

###### until: 3.0.0
###### id: ds.defaultValue.complex-object

Providing a non-primitive value as a `defaultValue` has been deprecated because
the provided value is shared between all instances of the model. Using a
non-primitive value, such as `defaultValue: []`, can lead to unexpected bugs when
that value is mutated.

If you wish to continue using a non-primitive value as the `defaultValue` for an
attribute, you should provide a function that returns the value:

```javascript
import DS from 'ember-data';

export default DS.Model.extend({
  username: DS.attr('string'),
  createdAt: DS.attr('date', {
    defaultValue() {
      return new Date();
    }
  })
});
```

### Deprecations Added in Ember Data 2.6

#### RESTSerializer.normalizeHash

###### until: 3.0.0
###### id: ds.serializer.normalize-hash-deprecated

`RESTSerializer.normalizeHash` has been deprecated in favor of using `normalize`.

If you had this:

```javascript
import DS from 'ember-data';

export default DS.RESTSerializer.extend({
  normalizeHash: {
    _id: function(hash) {
      hash.id = hash._id;
      delete hash._id;<commit_msg>Add deprecation guide for RESTSerializer.keyForPolymorphicType (#2755)<commit_after>---
title: Deprecations for Ember Data v2.x
alias: guides/deprecations/
layout: deprecations
---

## Deprecations Added in Ember Data 2.x

### Deprecations Added in Ember Data 2.3

#### Non-primitive defaultValue for Model Attributes

###### until: 3.0.0
###### id: ds.defaultValue.complex-object

Providing a non-primitive value as a `defaultValue` has been deprecated because
the provided value is shared between all instances of the model. Using a
non-primitive value, such as `defaultValue: []`, can lead to unexpected bugs when
that value is mutated.

If you wish to continue using a non-primitive value as the `defaultValue` for an
attribute, you should provide a function that returns the value:

```javascript
import DS from 'ember-data';

export default DS.Model.extend({
  username: DS.attr('string'),
  createdAt: DS.attr('date', {
    defaultValue() {
      return new Date();
    }
  })
});
```

#### RESTSerializer.keyForPolymorphicType

###### until: 3.0.0
###### id: ds.rest-serializer.deprecated-key-for-polymorphic-type

Previous versions of the
[`RESTSerializer`](http://emberjs.com/api/data/classes/DS.RESTSerializer.html)
relied on
[`keyForAttribute`](http://emberjs.com/api/data/classes/DS.RESTSerializer.html#method_keyForAttribute)
to determine the type key used for serializing polymorphic relationships. This
behavior has been deprecated in favor of using
[`keyForPolymorphicType`](http://emberjs.com/api/data/classes/DS.RESTSerializer.html#method_keyForPolymorphicType).
The benefit of having this additional hook is that you can customize the type
key separately from the key used for the relationship.

For example, given the following model:

```javascript
// app/models/comment.js

import DS from 'ember-data';

export default DS.Model.extend({
  commentable: belongsTo('commentable', { polymorphic: true }),
  body: DS.attr('string')
});
```

When using the `RESTSerializer`, Ember Data expects a payload that looks similar
the following:

```javascript
{
  "comment": {
    "id": "1",
    "commentable": "123",
    "commentableType": "movie", // ${keyForAttribute}Type
    "body": "I'll be back"
  },
  "movie": {
    "id": "123",
    "title": "The Terminator"
  }
}
```

If your API instead responds with a key that doesn't follow the pattern of
`${keyForAttribute}Type`:

```javascript
{
  "comment": {
    "id": "1",
    "commentable": "123",
    "commentKind": "movie", // custom keyForPolymorphicType needed
    "body": "I'll be back"
  },
  "movie": {
    "id": "123",
    "title": "The Terminator"
  }
}
```

You can now override the `keyForPolymorphicType` hook in your serializer to
accommodate:

```javascript
import DS from 'ember-data';

export default DS.RESTSerializer.extend({
  keyForPolymorphicType: function() {
    return 'commentKind';
  }
});
```

### Deprecations Added in Ember Data 2.6

#### RESTSerializer.normalizeHash

###### until: 3.0.0
###### id: ds.serializer.normalize-hash-deprecated

`RESTSerializer.normalizeHash` has been deprecated in favor of using `normalize`.

If you had this:

```javascript
import DS from 'ember-data';

export default DS.RESTSerializer.extend({
  normalizeHash: {
    _id: function(hash) {
      hash.id = hash._id;
      delete hash._id;
{'fraction_non_alphanumeric': 0.12927350427350429, 'fraction_numerical': 0.009615384615384616, 'mean_word_length': 4.313280363223609, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6636180', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1404, 'n_words': 474}