title: Ember Rails model relationship
body: <p>I have inherited an Ember.js application built on top of a Rails API. This was originally running the following:</p>
  
  <pre><code>Ember.VERSION : 1.0.0 ember.js
  DEBUG: Handlebars.VERSION : 1.0.0 ember.js
  DEBUG: jQuery.VERSION : 1.10.2   
  </code></pre>
  
  <p>but these have been updated to the following:</p>
  
  <pre><code>Ember      : 1.7.1+pre.f095a455 ember.js
  DEBUG: Ember Data : 1.0.0-beta.10+canary.30d6bf849b ember.js
  DEBUG: Handlebars : 1.3.0 ember.js
  </code></pre>
  
  <p>using the ember-rails gem.</p>
  
  <p>I am falling into a big blocker issue when trying to save a section model. Each section has a relationship with the row model:</p>
  
  <pre><code>row: DS.belongsTo('row', { async: true })
  </code></pre>
  
  <p>and the row model in return:</p>
  
  <pre><code>sections: DS.hasMany('section', { async: true })
  </code></pre>
  
  <p>Saving a new section runs the following function in a controller. The row class is being sent through and applied to an object before that object is being sent into the createRecord method.</p>
  
  <pre><code>_createSection: function(row, new_section_data){
    var store = this.get('store');
    new_section_data.width    = this.getNewSectionWidth(row);
    new_section_data.position = this.getNewSectionPosition(row);
    new_section_data.row      = row;
  
    var new_section = store.createRecord('section', new_section_data);
  
    console.log(' returned new_section ');
    console.log(new_section);
    new_section.save().then(function () {
      console.log('saved');
      new_section.set('set_as_selected', true);
  
      console.log(' new_section post save ');
      console.log(new_section);
  
    }, function () {
      console.log('new section save failure');
    });
  
    return new_section;
  },
  </code></pre>
  
  <p>The problem exists as soon as the model is created. The row is not actually being applied correctly to the model and therefore the Rails API request is not working and the section is not being saved.</p>
  
  <p>The data held in the new_section object prior to the createRecord request is as below:</p>
  
  <pre><code>html: "&lt;p&gt;New section&lt;/p&gt;"
  position: 3
  row: Class
  section_type_type: "TextSection"
  width: 6
  </code></pre>
  
  <p>This is the row class attached in the above code (with expanded _data node):</p>
  
  <pre><code>__ember1414408746094: "ember791"
  __ember_meta__: Object
  __nextSuper: undefined
  _attributes: Object
  _changesToSync: Object
  _data: Object
    id: 1
    page: Class
    page_id: 1
    position: 1
    sections: Array[2]
    style: null
    __proto__: Object
  _deferredTriggers: Array[0]
  _hasHadSections: true
  _inFlightAttributes: Object
  _relationships: Object
  _updatingRecordArraysLater: false
  container: Container
  currentState: Object
  defaultStyleObject: Object
  id: "1"
  store: Class
  updateTimeout: 7
  __proto__: Class
  section_type_type: "TextSection"
  width: 6
  </code></pre>
  
  <p>However, the following is the _data node from the returned new_section variable:</p>
  
  <pre><code>_data: Object
    contact_form_fields: Array[0]
    created_at: "2014-10-27T11:14:39.000Z"
    deleted_at: null
    gallery_images: Array[0]
    heading_visible: false
    height: null
    html: "&lt;p&gt;New section&lt;/p&gt;"
    id: 21
    position: 3
    row: null
    section_type_id: 19
    section_type_type: "TextSection"
    style: null
    updated_at: "2014-10-27T11:14:39.000Z"
    width: 6
  </code></pre>
  
  <p>Here you can see the row value is null.</p>
  
  <p>I am having difficulty (big) trying to figure out where this issue is happening. This may be related to the Ember data updates (this was originally built using a much older version) but I'm afraid I dont have the knowledge to understand what changed and why this is happening.</p>
  
  <p>Any help anyone can provide would be very useful, thank you.</p>