Mads K
Mads K

Reputation: 837

Ember Data rewrite URL

I have the following setup:

App.Router.map(function() {
    this.route('tab', { 'path' : 'tab/:which' });
});

App.ApplicationStore = DS.Store.extend({});
App.ApplicationAdapter = DS.RESTAdapter.extend({
    host: '../api'
});

App.TabAdapter = DS.RESTAdapter.extend({
  find: function(store, type, id) {

    alert("I doesn't get invoked");

    return this._super(store, type, id);
  }
});

App.TabRoute = Ember.Route.extend({
  model: function(params) {
    return this.store.find('emails', {tab: "inbox"});
  }
});

And when visiting the route #/tab/inbox i wanna rewrite the URL for the endpoint from http://localhost/ba/api/emails?tab=inboxinto http://localhost/ba/api/emails/inbox. Therefore i'm overriding the find()-method on the TabAdapter, but when this.store.find('emails', {tab: "inbox"}); runs, it doesn't enter my overridden method(and my test-alert doesn't get invoked).

Why does my overridden find()-method not get invoked?

Upvotes: 1

Views: 464

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

you're overriding the wrong find method. You're finding by query, not id and should be overriding that method

 findQuery: function(store, type, query) {
    // Do your thing here
    return this.ajax(this.buildURL(type.typeKey), 'GET', { data: query });
 }

And you're using a TabAdapter which would be specific to models of type tab not of type email(s). You should be creating a Email(s)Adapter. The general convention is for a model to be singular btw.

See also: How do you create a custom adapter for ember.js?

Upvotes: 2

Related Questions