Exclude model properties when saving with Ember-Data
ember.js, javascript
Solution
You can override the `serializeAttribute` function on the `Serializer`:
App.PhotoSerializer = DS.DjangoRESTSerializer.extend({
serializeAttribute: function(record, json, key, attribute) {
if (attribute.name !== 'image') {
this._super(record, json, key, attribute);
}
}
});
Problem
I have a model that has an `image` property. When saving images I would like to not Post that property to the endpoint. I was thinking perhaps I could `.set` the changes on everything beside the `image` property then save. But save still posts everything. Also, my Adapter supports PATCH so I can successfully save portions of the model. My model ``` App.Photo = DS.Model.extend({ title: attr(), description: attr(), image: attr(), authors: hasMany('author'), imageURL: function() { return document.location.origin + '/media/' + this.get('image'); }.property('image'), created: attr('date') }); ``` My Controller ``` App.PhotoController = Ember.ArrayController.extend({ actions: { save: function() { this.get('model').save().then(function(success) { self.transitionToRoute('photos').then(function() { }); }); } } }); ```