If you imagine two models defined thus:
App.User = DS.Model.extend({
emails: DS.hasMany('email', {embedded: 'always'}),
});
App.Email = DS.Model.extend({
address: DS.attr('string'),
alias: DS.attr('string'),
user: DS.belongsTo('user')
});
... and a REST Adapter:
App.UserAdapter = DS.RESTAdapter.extend({
url: 'http://whatever.com',
namespace: 'api/v1'
});
... with routing set up like so:
App.Router.map(function () {
this.route('index', { path: '/' });
this.resource('users', function () {
this.route('index');
this.route('add');
this.resource('user', { path: ':user_id' }, function () {
this.route('delete');
this.route('edit');
this.resource('emails', function () {
this.route('index');
this.route('add');
this.resource('email', { path: ':email_id' }, function () {
this.route('delete');
this.route('edit');
});
});
});
});
});
... and a controller action to save the edited email, which looks like this:
App.EmailEditController = Ember.ObjectController.extend({
actions: {
save: function () {
var self = this;
var email = this.get('model');
email.save().then(function(){
self.transitionToRoute('email', email);
});
}
}
});
The issue is this...
The PUT request is being sent to: http://whatever.com/api/v1/emails/[email_id]
However the correct API endpoint is: http://whatever.com/api/v1/users/[user_id]/emails/[email_id]
What is the correct way to remedy this issue?