Update below
I found a solution but I don't know if it is really the way to go. First I setup the route with a findQuery call:
App.UserCustomRoutesRoute = Em.Route.extend({
model: function() {
return this.store.find('user_custom_route', {user_id: this.controllerFor('user').get('user_id')});
}
});
Then I hooked into the adapter methods which configure the get request (findQuery and buildUrl).
App.UserCustomRouteAdapter = DS.RESTAdapter.extend({
buildURL: function(type, id) {
return 'users/' + id + '/routes';
},
findQuery: function(store, type, query) {
return this.ajax(this.buildURL(type.typeKey, query.user_id), 'GET');
}
});
Setup like this the request has the form of 'users/:user_id/routes'.
Update
I had to change the model method of the App.UserCustomRoutesRoute
. Most of the times user_id
at App.UserController
isn't yet set when App.UserCustomRoutesRoute
is called (p.e. when a user enters the site via its related address ('url#/users/:user_id/custom_routes'). So I had to put a authentication check which replies the user_id
if successful before the call to the related store.
App.UserCustomRoutesRoute = Em.Route.extend({
model: function() {
var self = this;
console.log('user custom routes route');
return Em.$.get('loggedIn').then(function(promise) {
return self.store.find('user_custom_route', {user_id: promise.user_id});
});
}
});