title: Ember - after saving model, how to get id in success callback from promise
body: <p>Simple scenario in Ember-1.9.1, Ember-Data 1.0.0-beta.14.1:</p>
  
  <p>Template form:</p>
  
  <pre><code>form
    fieldset
      dl
        dt: label First Name:
        dd: view Ember.TextField value=fields.first_name classNames='form-control'
  
      dl
        dt: label Last Name:
        dd: view Ember.TextField value=fields.last_name classNames='form-control'
  
      dl
        dt: label Sex:
        dd: view Ember.Select content=App.Patient.SEX prompt='Select a sex.' value=fields.sex classNames='form-control'
  
      dl
        dt: label Date of Birth:
        dd: view Ember.TextField value=fields.date_of_birth type="date" classNames='form-control'
  
      dl
        dt: label Insurance Provider:
        dd {{view Ember.Select content=insuranceProviders prompt='Select an insurance provider.' optionLabelPath='content.name' optionValuePath='content.id' value=currentInsuranceProvider.id classNames='form-control'}}
      dl
        dt: label Insurance Policy Number:
        dd: view Ember.TextField value=fields.insurance_policy_number classNames='form-control'
  
    fieldset.actions
      input type='submit' value='Create Patient' click="createPatient" class='btn btn-default'
      '
      a.cancel href="#" click="cancel" cancel
  </code></pre>
  
  <p>Controller Action:</p>
  
  <pre><code>createPatient: function() {
    var self = this;
    var fields = this.get('fields')
    fields.insurance_provider_id = this.currentInsuranceProvider.id
  
    if (App.Patient.valid(fields)) {
      var patient = this.store.createRecord('patient', fields)
  
      patient.set('date_of_birth', new Date(moment(fields.date_of_birth).format()));
  
      patient.set('insurance_provider', this.insuranceProviders.findBy('id', this.currentInsuranceProvider.id));
  
      patient.save().then(function(savedPatient){
        debugger
        self.transitionToRoute('patient', savedPatient);
      }).catch(failure);
  
      function failure(reason) {
        this.set('showError', true);
      }
    } else {
      this.set('showError', true)
    }
  }
  </code></pre>
  
  <p>Show 'patient' Route:</p>
  
  <pre><code>App.PatientRoute = Ember.Route.extend({
     model: function(params) { return this.store.find('patient', params.id); }
  })
  </code></pre>
  
  <p>Returned in the JS console:</p>
  
  <p><code>&gt; savedPatient</code></p>
  
  <p><code>&lt; Class {id: null, store: Class, container: Container, _changesToSync:   Object, _deferredTriggers: Array[0]…}</code></p>
  
  <p><code>&gt; savedPatient.get('id')</code></p>
  
  <p><code>&lt; null</code></p>
  
  <p>Why can't I get the id of the saved model in the success callback (where the debugger statement is) ? It does transition successfully, but with a null id in the route. This then causes problems if you want to edit the newly created model, after transitioning.</p>
  
  <p>Have also tried reloading the savedModel in the callback, which is not actually possible without the model's id. It seems as though the id isn't available until the Store is reloaded on the synchronous page refresh, updating it with the server and the server's id for the model. How is this possible to update the store within the callback?</p>
  
  <p>UPDATED</p>
  
  <p>Answer: Rails backend wasn't rendering the proper JSON.</p>
  
  <pre><code>def create
    patient = Patient.create(patient_params)
    render json: { :patient =&gt; [patient] }
  end
  </code></pre>