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() {
});
});
}
}
});
I think since this PR on Ember there is a better way to handle the exclusion of an attribute.
import DS from 'ember-data';
export default DS.JSONSerializer.extend({
attrs: {
image: {serialize: false}
}
});
If you have more than one attribute to exclude the above code looks cleaner. Also have a look on the documentation of DS.JSONSerializer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With