I have a model hook that returns a list of reviews from the data store. On that same page, I have a review form. When the form is submitted, I call an action on the controller and I need to call createRecord() on the store. Normally I would return a created record from a model hook but my model hook is already taken. What is the best approach here?
I think calling the action on controller is the right approach.
actions: {
submitForm: function() {
var store = this.get('store');
var review = store.createRecord('review');
review.save().then(function(){
//success
}, function(){
//error
store.deleteRecord(review);
});
}
}
1 Like
Thanks! I didn’t know that you can access the store from a controller using this.get(‘store’).
You can get “store” in controllers, routes and data-adapters by this.get(‘store’).