How to set custom path and JSON root for Ember Data model using ActiveModelAdapter?

I’ve got App.Channel model and I’d like to create a separate App.PlayerChannel model, so that store.find('player_channel') would make request to host + namespace + /channels URL and in response I’d get channels as JSON root.

How to set it up if I’m using ActiveModelAdapter?

Hi @szimek

You can do this by creating a type specific adapter for your PlayerChannel model. It will likely look something like

App.PlayerChannelAdapter = DS.ActiveModelAdapter.extend({
    host: 'host',
    namespace: 'namespace', 
    pathForType: function(type) {
        return 'channels';
    }
});
3 Likes

I my app I have a single application-level adapter that handles all the types in a switch statement.

Thanks guys! I’ll probably go with a separate adapter - looks like a cleaner approach.