Reputation: 58
I'm having trouble getting my Route's model and setupController hooks to work correctly. I'm still relatively new to ember. Here's my code
IS.AlbumsRoute = Ember.Route.extend({
model: function (params) {
return IS.Album.find(params.album_id);
},
setupController: function(controller, user) {
var controller = this.controllerFor("application");
var data = controller.get("currentUser").get('albums');
controller.set('content', data);
}
}
And my models look like this
IS.User = DS.Model.extend({
email: DS.attr('string'),
password: DS.attr('string'),
albums: DS.hasMany('IS.Album'),
});
IS.Album = DS.Model.extend({
name: DS.attr('string'),
description: DS.attr('string'),
user: DS.belongsTo('IS.User')
});
While this works, an extra query to my api is sent to "api/albums" preceding the query that actually gets the correct data (at url "api/albums/ids[]=0&ids[]=1"). Is there anyway to stop this extra query form happening?
Upvotes: 1
Views: 1146
Reputation: 1178
Have you tried this?
IS.AlbumsRoute = Ember.Route.extend({
model: function () {
var controller = this.controllerFor("application");
return controller.get('currentUser.albums');
}
}
Upvotes: 3