# Saving models with only changed attributes/relationships

**URL:** <https://discuss.emberjs.com/t/saving-models-with-only-changed-attributes-relationships/3568>\
**Category:** Ember Data\
**Created:** [December 11, 2013, 6:38am UTC](https://discuss.emberjs.com/t/saving-models-with-only-changed-attributes-relationships/3568 "2013-12-11T06:38:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rhinon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rhinon/32/5164_2.png) [@Rhinon](https://discuss.emberjs.com/u/Rhinon)\
**Post date:** [December 11, 2013, 6:38am UTC](https://discuss.emberjs.com/t/saving-models-with-only-changed-attributes-relationships/3568/1 "2013-12-11T06:38:16Z")

</div>

Any recommendations on how this may be done?

How reasonable/feasible is this right now with the current state of ember-data?

---

<div class="post-metadata">

**Author:** ![radq](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/radq/32/4898_2.png) [@radq](https://discuss.emberjs.com/u/radq)\
**Post date:** [December 31, 2013, 1:42am UTC](https://discuss.emberjs.com/t/saving-models-with-only-changed-attributes-relationships/3568/2 "2013-12-31T01:42:11Z")

</div>

You can do this by overriding the serializer.

```coffeescript
Hummingbird.ApplicationSerializer = DS.ActiveModelSerializer.extend
  serialize: (record, options) ->
    json = {}

    if options and options.includeId
      if record.get('id')
        json[this.get('primaryKey')] = record.get('id')

    changedAttributes = Object.keys record.get('_inFlightAttributes')

    record.eachAttribute (key, attribute) ->
      if changedAttributes.indexOf(key) != -1
        @serializeAttribute(record, json, key, attribute)
    , this

    record.eachRelationship (key, relationship) ->
      if relationship.kind == 'belongsTo'
        @serializeBelongsTo(record, json, relationship)
      else if relationship.kind == 'hasMany'
        @serializeHasMany(record, json, relationship)
    , this

    json

```

---

<div class="post-metadata">

**Author:** ![josemarluedke](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/josemarluedke/32/13803_2.png) [@josemarluedke](https://discuss.emberjs.com/u/josemarluedke)\
**Post date:** [July 10, 2014, 3:34pm UTC](https://discuss.emberjs.com/t/saving-models-with-only-changed-attributes-relationships/3568/3 "2014-07-10T15:34:10Z")

</div>

Seems that radq’s solution does not work anymore with ember-data `1.0.0-beta.8`. Any one has any tips to make ember-data save only the changed attributes? I couldn’t find any solution for this.

Thanks.

---

<div class="post-metadata">

**Author:** ![joshuaob](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@joshuaob](https://discuss.emberjs.com/u/joshuaob)\
**Post date:** [March 24, 2017, 7:23pm UTC](https://discuss.emberjs.com/t/saving-models-with-only-changed-attributes-relationships/3568/4 "2017-03-24T19:23:13Z")

</div>

Hi all, I use the [ember-data-change-tracker](https://github.com/danielspaniel/ember-data-change-tracker) addon to accomplish this. I answered a similar question [here](https://discuss.emberjs.com/t/dirt-tracking-with-ember-data-only-save-dirty-properties/4191/33). Hope it helps
