Very new to Ember, and I am a bit confused on a few things when it comes to using ember-data. In general, I love the idea, but working with it has been frustrating and a bit baffling.
I have a route for showing all existing models for a resource, and a nested show route for loading details. On that page, I have a small form for adding new models, which will trigger an action handled by the route.
This was all surprisingly easy and straight forward. Now however, I feel like I hit a bit of a wall.
Should a creation form be backed by a model? Since there is only one model per controller, does that mean creation forms need to exist in their own route? It seems like a strange limitation.
When handling the create action, I am calling store.createRecord
, and then saving it. Which makes loads of sense if it saves successfully. If it doesn’t, do I need to manually remove the model from the store?. It would make much more sense to me to instantiate the model, and if that succeeds then add it to the store, but apparently it isn’t possible to instantiate models directly.
When the server responds with a 422, an exception is thrown by ember-data. Is that expected, or is there something I should be handling? More complex validation needs to happen server side, and validation failure is definitely not an exceptional situation, having exceptions being thrown feels like I’m missing something.
If there are errors added by the server, should I try to re-save the same model instance?
What is the recommended way to display server generated errors on a form?
Given how much effort has gone into having conventions, documentation, and tools for streamlining common tasks, it feels like the validation workflow is an area that is sorely lacking.