Posting to a Shallow Nested Route


I’m using shallow nested routes (Rails) for some of my models. I’m able to access children records by including a links hash in the JSON returned object like so:

  "companies": [
    "id": 1,
    "name": "Acme, Inc.",
    "links": {
      "locations": "/companies/1/locations"
    "location_ids": [

This works fine for GETs, but how would I do a POST against /companies/1/locations. Ember-Data tries to use /locations, which doesn’t exist. How do I get ember-data to use the links hash when creating a record?

BTW, my URLS look like so:

/companies/1/locations: GET

/companies/1/locations: POST

Then /locations/:id for PUT, GET (show), and DELETE


Apparently this can’t be accomplished with ember-data “as is”. I believe you need to extend the adapter to build the URL the way you want it.

Here it’s explained a nice trick to do it extending the generic RESTAdapter:

I did this only extending the createRecord for the POST route, since the updateRecord (PUT) and deleteRecord (DELETE) seem to work well if you use shallow nested routes. It worked for me!