In my Ember app, I have a nested hasMany relationships using ember-data like so workout->exercise->set
.
My API has nested JSON instead of sideloaded JSON, so to fetch an existing workout I use store.find('workout', id)
and override extractSingle
.
My problem is when building a new workout I need to prepopulate it with exercises and sets based on a workout plan that a user is following. On the server side, I just have a /new controller action that prepopulates everything and renders a template.
Now that I'm moving to Ember I need the same functionality, but can't seem to make it work. The first thing I tried was to use Ember.$.getJSON
to call a custom API endpoint in conjunction with pushPayload
. This doesn't work however, because pushPayload
bypasses extractSingle
which means I can't convert my nested JSON into side-loaded JSON.
The prepopulation logic is very complicated so I'd prefer not to duplicated it client side and retrieve it from the API. Any other ideas on how I could accomplish this using ember-data?