I want to be able to set my model dynamically depending on a record in the store - mainly because I want to control whether or not a form submission should be a POST or PUT.
export default Ember.Route.extend({
model: function() {
let bankAccount = this.store.get('bankAccount').objectAt(0);
if (bankAccount.is_connected) {
bankAccount = this.store.createRecord('bankAccount', { account_label: 'new' });
}
return Ember.RSVP.hash({
appState: this.get('appStates').currentAppState(),
user: this.store.findAll('user').thenGetFirst(),
bankAccount: bankAccount,
});
},
});
The issue is that let bankAccount = this.store.get('bankAccount').objectAt(0);
return null when I refresh the page.
However, if I run App.store.get('bankAccount').objectAt(0)
in my browser console, it returns the correct record.
What am I doing incorrectly?
Aucun commentaire:
Enregistrer un commentaire