Created
March 5, 2014 01:20
-
-
Save rwjblue/9359366 to your computer and use it in GitHub Desktop.
Custom Model Specific Adapters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// So you likely have an application adapter like so: | |
App.ApplicationAdapter = DS.ActiveModelAdapter.extend(); // could also be REST adapter | |
// And you have a model: | |
App.Comment = DS.Model.extend({ | |
text: DS.attr(), | |
createdBy: DS.attr() | |
}); | |
App.CommentsRoute = Ember.Route.extend({ | |
model: function(){ | |
// by default this will perform a GET request to your API endpoint | |
this.store.find('comment'); | |
} | |
}); | |
// BUT you want a POST, so just define a custom adapter for the comment model: | |
App.CommentAdapter = App.ApplicationAdapter.extend({ | |
// this gets called when you do not pass an ID to this.store.find | |
findAll: function(store, type) { | |
return this.ajax(this.buildURL(type.typeKey), 'POST'); | |
}, | |
// this gets called when you do pass an ID | |
find: function(store, type, id) { | |
return this.ajax(this.buildURL(type.typeKey, id), 'POST'); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment