Deewendra Shrestha
Deewendra Shrestha

Reputation: 2465

How to configure RESTAdapter based on model in ember.js

I wanted to set the RESTAdapter namespace based on the model. I tried to follow the example provided here: a link, but it seems like the registerAdapter function doesn't exist.

This is how my code looks:

AS.AnalyticsConfigRoute = Ember.Route.extend({
    model: function(param) {
        var store = this.get('store');
        return store.find('AnalyticsRun',param.runId);      
    }
});

//AS.AnalyticsRun is a model 
AS.Store.registerAdapter(AS.AnalyticsRun, DS.RESTAdapter.extend({
// implement adapter; in this case
    namespace: "/analytics/run"
}));

I am wondering if it is a version thing. I believe that I am using the latest version for everything. I am using ember data

//Version: v1.0.0-beta.1-140-ga51f29c

// Last commit: a51f29c (2013-09-07 16:34:55 -0700)

and ember:

// Version: v1.0.0

// Last commit: e2ea0cf (2013-08-31 23:47:39 -0700)

Your help will be much appreciated. Thanks.

Upvotes: 0

Views: 502

Answers (1)

Jeremy Green
Jeremy Green

Reputation: 8594

Checkout the TRANSITION doc for info about "Per Type Adapters" :

https://github.com/emberjs/data/blob/master/TRANSITION.md#per-type-adapters

You'll want to do something like this:

// This naming will automatically hook this Adapter to the
// AS.AnalyticsRun model
AS.AnalyticsRunAdapter = DS.RESTAdapter.extend({
  namespace: "/analytics/run"
});

Note that when calling find, you'll want to use the camel cased version of your model name. store.find('analyticsRun'), not store.find('AnalyticsRun').

Upvotes: 1

Related Questions