I have 2 models ledger hasMany players. Under the sub route ledger/26/players
my controller has an action to create a new player:
create: function() {
var newplayer = this.store.createRecord('player', {
name: this.get('newPlayerName'),
disabled: false
});
newplayer.set('ledger',this.get('ledger'));
console.log(newplayer.serialize());
newplayer.save().then( () => {
this.set('newPlayerName',null);
}, (err) => {
console.error(err);
});
}
}
logging serialize() shows a blank ledger object even if ledger is completely loaded:
In my player model I have:
ledger: belongsTo('ledger', {async: false})
while route is:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.modelFor('ledger').get('players');
},
setupController(controller,model) {
controller.set('model', model);
controller.set('ledger',this.modelFor('ledger'));
}
});
The wrong serialization causes the save()
call to fail as it generates a wrong endpoint:
http://localhost:3002//players
All this happens after transitioning directly from ledger creation and passing the ledger model to the route (no model reload). If I, instead, reload the whole route everything works! Please help
Aucun commentaire:
Enregistrer un commentaire