Fighting a REST adapter with Ember data and nested resources

I am really struggling with the Ember-data REST adapter and embedded resources and would appreciate any help ... I am using the latest version 1.0 (Embedded Ember-Ember-data) (version: 11).

I have two simple models:

App.User = DS.Model.extend({ name: DS.attr('string'), email: DS.attr('string'), schemes: DS.hasMany('App.Scheme') }); App.Scheme = DS.Model.extend({ name: DS.attr('string'), users: DS.hasMany('App.User') }); 

and simple nested routes:

 Router.map(function() { this.resource("user", { path: "users/:user_id" }, function() { this.resource("schemes"); }); }); 

I have a Rails 3 JSON API that has the following endpoints:

 /users/:user_id /users/:user_id/schemes 

When I go to users/:user_id/schemes in my ember application, I want to get all user schemes, but by default Ember-data /schemes requests that are not the endpoint in my API, I can add, but I need to user reach schemes, I have no concept of current_user, because I want to view any user and her schemes.

Is there a way to get Ember to look at /users/:user_id/schemes or add a request parameter to the ajax call by default Ember, for example: /schemes?user_id=:user_id ?

Alternatively, is there a way to add ajax to the request headers, which in turn, my rails API can read and configure the /schemes response accordingly?

+6
source share
1 answer

This feature seems to have been discussed quite a bit, but not yet implemented. This issue contains sample code for quick work.

You can also use:

 var userSchemes = App.Scheme.find({ used_id: 'id' }); 

request /schemes?user_id=id .

+4
source

All Articles