Nested 'Linked-list' model in Ember-data


I’ve been using Ember CLI to develop an API and it’s been interesting to get into the ‘ember way’ but I’ve found a quite tough situation I don’t know how I should proceed. I’ll present my models case:

  1. Let project be a model with several info attributes such as name.

  2. Let structureRow be another model with some info attributes, a parent structureRow and a next structureRow.

  3. A project holds a structurerow.

Now I think of two possible directions to address this:

  • I set up my backend API to give me the rendered structure of the project loaded, with all the relations resolved to certain depth instead of giving me references.

  • I set up my backend API to give me references only and resolve them as needed in the frontend. However, I don’t know how I could make it using ember-data, given the strong convention with routes and templates.

What would you recommend to I set this up in an ember-way instead of writing some arbitrary AJAX handling in a controller?


Either ways works. Personally I sideload data that I know I will need wherever possible to cut down on total requests. Eventually I may have it so that the api supports an include query param that specifies which things to sideload and which not to.

If you don’t want to sideload data / want tho front end to resolve the relationships add the async attribute to your belongs to or has many.

DS.belongsTo('parent', { async: true })

Thanks vablob, I’ll sideload relationships then. I was worried about having to many http requests by resolving every single relation on the frontend.

Just another question: if I sideload the data, will Ember notice it and populate de appropriate models or do I have to somehow tell Emeber I’m sideloading?

Assuming your json payload matches the adapter you’re using it should just work.

Nice, I just tried it and it simply works. Thanks!