Custom REST URL for a specific model

Is there a way in Ember to configure a custom REST url for a particular model?

As 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 comments to be retrieved via /rest/post/{id}/commentsinstead /rest/comments, which is the default behavior.
Is it possible to configure the rest url for one specific model?

+5
source share
2 answers

You can register an additional adapter and "combine" it into your model.

App.Store.registerAdapter('App.Post', DS.RESTAdapter.extend({
  url: "/rest/post/"
}));
+2
source

"hasMany" uri, REST? , api (django rest framework) uri, URL- , URL- "" "" (- rails devs , ).

( , hasMany, ). , , , .

11 ember- ( ​​ 12)

https://github.com/toranb/ember-data-django-rest-adapter/blob/master/tests/adapter.js

    findMany: function(store, type, ids, parent) {
        var json = {}
        , root = this.rootForType(type)
        , plural = this.pluralize(root)
        , ids = this.serializeIds(ids)
        , url = this.buildFindManyUrlWithParent(store, type, ids, parent);

        this.ajax(url, "GET", {
            success: function(pre_json) {
                json[plural] = pre_json;
                Ember.run(this, function(){
                    this.didFindMany(store, type, json);
                });
            }
        });
    },
+1

All Articles