2

We are using Ember together with Ember-Data and are stumped by following setup:

There is a parent object (Epic) which has a number of children (UserStory). We have modelled this accordingly using ember-data:

App.Epic = DS.Model.extend({
    name: DS.attr("string"),
    description: DS.attr("string"),
    project: DS.belongsTo("App.Project")
});

App.UserStory = DS.Model.extend({
    name: DS.attr("string"),
    description: DS.attr("string"),
    goal: DS.attr("string"),
    benefit: DS.attr("string"),
    epic: DS.belongsTo("App.Epic")
});

What we would like to achieve now, is that we a have a list of independent forms to edit the Epic inline with all of its UserStories. Obvisouly we would simply deliver all of the UserStories together with the Epic via the RESTAdapter. Yet we are afraid that this would lead to ugly update scenarios: changing one UserStory would trigger a update of the entire Epic with all of its UserStories. In our architecture a UserStory is an indepenent entity which should be maintained by a dedidacted REST service.

As an ember-newbie we would like to implement something in the lines of:

  • Load the Epic via ember-data
  • Extend the EpicController to load all UserStories into a separate model-(list).
  • Changes to the Epic via the dedicated form fire a change to the Epic Rest Service.
  • Magic: Changes to an individual UserStory form fire an isolated and individual change to the User Story Rest Service.

How can the magic be achieved?

Stefan
  • 990
  • 1
  • 6
  • 10
  • 1
    This seems to be the prime use case for side-loading, i.e. delivering the set of UserStories in the same API call as the Epic, but as a separate array instead of nesting. – Christopher Swasey Mar 06 '13 at 12:27

2 Answers2

1

Take a look at the controllerFor method:

http://emberjs.com/guides/routing/setting-up-a-controller/

commadelimited
  • 5,656
  • 6
  • 41
  • 77
0

this is kind of embarrassing, but what I wanted is exactly how ember-data behaves per default. All I needed to do, was to have the Epic REST-Service deliver the UserStory ids instead of the inline objects. Ember will get all children in one go - the URL setup is a bit ugly but works - and will use the UserStory rest-service to do the puts.

Ember has a steep but satisfying learning curve.

Thanks for your feedback.

Stefan

Stefan
  • 990
  • 1
  • 6
  • 10