Hello Ember Data World,
I have been studying custom adapters attempting to figure out how to override the save method.
From my understanding, it seems like you need to do something like this:
DS.RESTAdapter.extend({
save: function() { return this._super();}
})
However, when I attempted to invoke the save operation on my model object using:
model.save()
The store gets invoked directly and not my adapter custom code.
Has anyone attempted to do this before?
I am able to call the find method using the following code in the same adapter
findQuery: function(store, type, query) {
//debugger;
console.log("findQuery: Custom adapter called!");
return this.ajax(this.buildURL(type.typeKey), 'GET', { data: query });
}
save
is actually defined on the record, not the adapter. If you felt like overriding it you would do so in your model definition.
Here's an example of that:
App.Color = DS.Model.extend({
color: DS.attr(),
save: function(){
alert('save');
}
});
http://emberjs.jsbin.com/OxIDiVU/497/edit
Now if you felt like overriding what save eventually calls on the adapter you would need to update one of three methods, createRecord
, updateRecord
, deleteRecord
. They are pretty self explanatory in what they each should do when save is called. You would then follow a pattern such as you did above:
App.ApplicationAdapter= DS.RESTAdapter.extend({
updateRecord: function(){
alert('update record');
}
});
http://emberjs.jsbin.com/OxIDiVU/498/edit
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