title: Sending POST requests to a nested API endpoint URL using Ember Data
body: <p>I see several questions on SO attempting to solve this problem of sending POST requests to nested API resource routes.</p>
  
  <p>See:
  - [Sending REST requests to a nested API endpoint URL using Ember Data(<a href="https://stackoverflow.com/questions/21530833/sending-rest-requests-to-a-nested-api-endpoint-url-using-ember-data">Sending REST requests to a nested API endpoint URL using Ember Data</a>)
  - <a href="https://stackoverflow.com/questions/24486421/custom-request-urls-in-ember-model">Custom request URLs in Ember model</a></p>
  
  <p>I've started overloading the createRecord, updateRecord, and deleteRecord methods on the RESTAdapter to attempt some sort of hackery solution to building the correct URL. Now, using a method similar to <a href="https://stackoverflow.com/a/22806798/144609">this</a> is the route I've taken so far. </p>
  
  <p>Here is the updateRecord method in their solution:</p>
  
  <pre><code>App.UserAdapter = DS.RESTAdapter.extend({
  
      updateRecord: function(store, type, record) {
  
          if(!record.get('parent') || null === record.get('parent')){
              return this._super(store, type, record);
          }
  
          var data = {};
          var serializer = store.serializerFor(type.typeKey);
  
          var parent_type = record.get('parent');
          var parent_id = record.get(parent_type).get('id');
          var child_parts = Ember.String.decamelize(type.typeKey).split('_');
  
          var path = Ember.String.pluralize(parent_type) + '/' + parent_id + '/' + Ember.String.pluralize(child_parts.pop());
  
          serializer.serializeIntoHash(data, type, record);
          var id = record.get('id');
  
          return this.ajax(this.buildURL(path, id), "PUT", { data: data });
      }
      ....
  });
  </code></pre>
  
  <p>This method should work great in tandem with adding the <code>parent</code> type to the model and ensuring the related parent model id is also represented on the model. For PUT and DELETE requests, this shouldn't be a problem, as we already have the parent ID relation on the object in store.</p>
  
  <p>Project model:</p>
  
  <pre><code>App.ProjectModel = DS.Model.extend({
      name: DS.attr('string'),
      createdAt: DS.attr('date'),
      updatedAt: DS.attr('date'),
      workspace : DS.belongsTo('workspace'),
      parent: 'workspace',
      ....
  });
  </code></pre>
  
  <p>Where this method appears to go awry for me is in creating new resources with a post. I've attempted it, but since the payload hasn't been returned from the API server with the related parent ID, I actually don't have access to it.</p>
  
  <p>Here's my crappy first attempt, that doesn't work. The workspace id always returns null.</p>
  
  <pre><code>createRecord: function(store, type, record) {
      if (!record.get('parent') || null === record.get('parent')){
          return this._super(store, type, record);
      }
  
      var data = {};
      var serializer = store.serializerFor(type.typeKey);
  
      var parent_type = record.get('parent');
      var parent_id = record.get(parent_type).get('id');
  
      var path = Ember.String.pluralize(parent_type) + '/' + parent_id + '/' + type.typeKey);
  
      serializer.serializeIntoHash(data, type, record, { includeId: true });
  
      return this.ajax(this._buildURL(path, null), "POST", { data: data });
  },
  </code></pre>
  
  <p>Got any thoughts on how I can get the parent ID, before I have a saved record?</p>