Skip to content

Instantly share code, notes, and snippets.

@pekhee
Created June 11, 2014 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pekhee/696f90335d5c153c1839 to your computer and use it in GitHub Desktop.
Save pekhee/696f90335d5c153c1839 to your computer and use it in GitHub Desktop.
Getting Custom Routes, or Nested Routes to Work in Ember Data.

Say a User has many Posts.

App.User = DS.Model.extend({
  posts: DS.hasMany('post', {async: true})
});


App.Post = DS.Model.extend({
  user: DS.belongsTo('user', {async: true})
});

If your server responds like this

GET /users
{
  users: [
    {
      id: 1,
      comments: '/users/1/comments'
    }
  ]
}

Ember Data will issue another request to '/users/1/comments' whenever comments association is accessed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment