Ember JS : Creating nested urls for relationships REST-style

I’ve been working on a project in Ember JS with the Ember-client extension for a while now. Ember is very frustrating to work with because of the lack of documentation.

I was recently looking for a way to have Ember use urls for loading and saving resources from a REST-api using the same conventions used by api’s like the ones Facebook and Twitter use.

For example, requesting the comments for a post would have an endpoint like this:


Unfortunately Ember will just post the user id to this endpoint:


There is a way to have Ember use /posts/{ID}/comments as endpoint but that requires the payload from the api for a post to contain the property ‘links’, containing the desired endpoint. To me this seems undesirable; endpoints should be derived from conventions. Besides, if you have no control over the api then you have no control over this ‘links’ property

You could add the ‘links’ property to the payload by overriding Ember’s RESTAdapter or RESTSerializer but that is a difficult place to do that.

I analysed what Ember does in the background when it finds the ‘links’ property on a payload : it creates relationships in the corresponding model. I managed to create an override that changes the ‘link’ property of the corresponding relationship.

This is my code:

I’m not really happy with this solution because manually changing the ‘link’ property after ember created the relationship is far from ideal. But in the mean time, untill I find a better approach I’m sticking to this in order to get my application to work.