Need a new record and a list of records on a model hook ... or am I doing this wrong?


#1

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?


#2

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);
         });
     }
 }

#3

Thanks! I didn’t know that you can access the store from a controller using this.get(‘store’).


#4

You can get “store” in controllers, routes and data-adapters by this.get(‘store’).