Saving models with only changed attributes/relationships

Any recommendations on how this may be done?

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

You can do this by overriding the serializer.

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
2 Likes

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.

Hi all, I use the ember-data-change-tracker addon to accomplish this. I answered a similar question here. Hope it helps