1

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?

Mads K
  • 847
  • 2
  • 14
  • 32
  • I'm new to Ember, but is there a TabsController and Tab model classes as well? – GSP Nov 04 '14 at 13:27
  • Yes there are, but they are currently empty, and Ember automatically creates the controller for the route, if it's not specified. App.TabController = Ember.Controller.extend({}); App.Tab = DS.Model.extend({}); – Mads K Nov 04 '14 at 13:31

1 Answers1

2

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?

Community
  • 1
  • 1
Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
  • It still doesn't get invoked? Thats really strange. App.TabAdapter = DS.RESTAdapter.extend({ findQuery: function(store, type, query) { alert("I doesn't get invoked"); return this.ajax(this.buildURL(type.typeKey), 'GET', { data: query }); } }); – Mads K Nov 04 '14 at 14:06