Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom REST url for specific Model

Is there a way in Ember to configure a custom REST url for a specific Model?

Like with this model:

App.Post = DS.Model.extend({
    title: DS.attr('string'),
    comments: DS.hasMany('App.Comment')
});
App.Comment = DS.Model.extend({
    content: DS.attr('string'),
    post: DS.belongsTo('App.Post')
});

And this Store:

app.Store = DS.Store.extend({
    revision : 11,
    adapter : DS.RESTAdapter.extend({
        namespace : 'rest'
    })
});

I want that the comments are retrieved via /rest/post/{id}/comments instead of /rest/comments which is the default behaviour.
Is it possible to configure a rest-url for one specific Model?

like image 505
Willem de Wit Avatar asked Oct 22 '22 15:10

Willem de Wit


1 Answers

You can register an additional adapter and 'scope' it to your model.

App.Store.registerAdapter('App.Post', DS.RESTAdapter.extend({
  url: "/rest/post/"
}));
like image 126
jdcravens Avatar answered Oct 25 '22 18:10

jdcravens