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

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’).

https://github.com/emberjs/data/blob/v1.0.0-beta.18/packages/ember-data/lib/initializers/store-injections.js