Should hasMany relationships generate a smart url


I am working on optimizing my backend json api. The biggest bottleneck is serializing all the relationship ids. I have had success using the links option and generating links like “posts/:post_id/comments” or “comments?post_id=:post_id”. But I don’t think it is optimal to have the backend serialize the url in cases where the url is obvious.

I would like to extend ember-data to build the url automatically when the relationship is asynchronous. All the info needed is available or could be customized by adding options like ‘foreign_key’, ‘primary_key’ to the hasMany definition.

On a related note I am also thinking of extending the reload method to append the a timestamp to the request so the backend could return just the objects that have changed. This might be better implemented in the controller, but just a thought.

Reloading a relationship would do something like:

var query = {this.foreign_key:, updated_after: this.max_timestamp} 'comment', query , function(record){
   return record.get(this.foreign_key) ==;

Regarding the url has any one done anything similar? Is this something that should be considered being built in?


I think what you’re asking for (for the first part at least) is part of the jsonapi spec…and it looks some wonderful folks have created an adapter that adheres to that spec. (Haven’t actually looked at the adapter to see what support is actually built in).


Currently if you know the form of the link you could put in the normalize hook client side. As soon as someone implements this should be easier


@terzicigor okay cool the normalize hook will work for now. I’ll try and give that issue a shot this week.