[This is about the new 1.0.0-pre.4+ router.]
I want to return from an Ember Route's model
method a record that needs asynchronous callbacks to load, for instance because it requires that we load multiple (nested) models. What's the best way to do this?
Here is sample code from a hypothetical blog app that illustrates the problem:
App.Router.map ->
@resource 'filteredArticles', path: '/:filter'
App.FilteredArticlesRoute = Ember.Route.extend
model: (params) ->
blog = App.Blog.find(1) # get the user's Blog singleton
property = switch params.filter
when 'published' then 'publishedArticles'
when 'draft' then 'drafts'
when 'all' then 'articles'
# Return the list of articles from the `blog` record.
# But `blog` hasn't necessarily finished loading :(
blog.get(property)
blog.get(property)
it will return another promise, which will be fetched async. – SpringcleanApp.Blog.find(1).get('articles')
yields a non-empty array. – HarryisLoaded
(gist.github.com/domchristie/4774472): a pattern inspired by the Discourse source code. Could you be experiencing this issue? – Gombosi