title: Nested XML data and ExtJS model associations
body: <p>I'm trying to map XML data to a series of models in ExtJS. I'm able to extract the data from the toplevel model, however, the associations with it fail to retrieve the necessary data.</p>
  
  <p>Here are all of my models:</p>
  
  <pre class="lang-js prettyprint-override"><code>Ext.define('app.model.ProductType', {
      extend: 'Ext.data.Model',
      idProperty: 'id',
      fields: [{
          name: 'id',
          mapping: 'id',
          type: 'int'
      }, {
          name: 'name',
          mapping: 'name',
          type: 'string'
      }, {
          name: 'sometag',
          mapping: 'sometag',
          type: 'string'
      }],
      associations: [{
          type: 'hasMany',
          model: 'app.model.Address',
          name: 'addresses',
          autoLoad: true,
          reader: {
              type: 'xml',
              record: 'address',
              root: 'addressList'
          }
      }, {
          type: 'hasMany',
          model: 'app.model.PhoneContact',
          name: 'contacts',
          autoLoad: true,
          reader: {
              type: 'xml',
              record: 'phoneContact',
              root: 'phoneContactList'
          }
      }, {
          type: 'hasOne',
          model: 'app.model.OneToOne',
          name: 'oneToOne',
          autoLoad: true,
          reader: {
              type: 'xml',
              record: 'oneToOne'
          }
      }],
      proxy: {
          type: 'ajax',
          url: 'data/example.xml',
          reader: {
              type: 'xml',
              record: 'ProductType',
              root: 'ProductResultSet'
          }
      }
  });
  </code></pre>
  
  <p>Address:</p>
  
  <pre class="lang-js prettyprint-override"><code>Ext.define('app.model.Address', {
      extend: 'Ext.data.Model',
      fields: [{
          name: 'city',
          mapping: 'city',
          type: 'string'
      }, {
          name: 'street',
          mapping: 'street',
          type: 'string'
      }],
      associations: [{
          type: 'belongsTo',
          model: 'app.model.ProductType'
      }]
  });
  </code></pre>
  
  <p>PhoneContact:</p>
  
  <pre class="lang-js prettyprint-override"><code>Ext.define('app.model.PhoneContact', {
      extend: 'Ext.data.Model',
      fields: [{
          name: 'primary',
          mapping: 'primary',
          type: 'string'
      }, {
          name: 'cell',
          mapping: 'cell',
          type: 'string'
      }],
      associations: [{
          type: 'belongsTo',
          model: 'app.model.ProductType'
      }]
  });
  </code></pre>
  
  <p>OneToOne:</p>
  
  <pre class="lang-js prettyprint-override"><code>Ext.define('app.model.OneToOne', {
      extend: 'Ext.data.Model',
      fields: [{
          name: 'first',
          mapping: 'firstfield',
          type: 'string'
      }, {
          name: 'second',
          mapping: 'secondfield',
          type: 'string'
      }],
      associations: [{
          type: 'belongsTo',
          model: 'app.model.ProductType'
      }]
  });
  </code></pre>
  
  <p>Here's my app.js</p>
  
  <pre class="lang-js prettyprint-override"><code>Ext.Loader.setConfig({
      enabled: true
  });
  
  Ext.application({
      name: 'app',
      autoCreateViewport: false,
      requires: ['app.model.ProductType', 'app.model.Address', 'app.model.PhoneContact', 'app.model.OneToOne', 'app.store.ProductTypeStore'],
      launch: function () {
          app.model.ProductType.load(55, {
              scope: this,
              callback: function (record, operation) {
                  console.log('Record Addresses:');
                  console.log(record.addresses());
              }
          });
  
          var s = app.store.ProductTypeStore.create();
          s.on('load', this.wiggidy, this);
          s.load();
      },
      wiggidy: function (store, records, success, eOpts) {
          var rec = store.getAt(0);
          console.log('Associated Data:');
          console.log(rec.getAssociatedData());
      }
  });
  </code></pre>
  
  <p>And finally, example.xml</p>
  
  <pre><code>&lt;ProductResultSet&gt;
  &lt;ProductType&gt;
      &lt;id&gt;55&lt;/id&gt;
      &lt;name&gt;Product Name&lt;/name&gt;
      &lt;sometag&gt;asdf&lt;/sometag&gt;
      &lt;addressList&gt;
          &lt;address&gt;
              &lt;street&gt;12345 a&lt;/street&gt;
              &lt;city&gt;myCity&lt;/city&gt;
          &lt;/address&gt;
          &lt;address&gt;
              &lt;street&gt;234567 b&lt;/street&gt;
              &lt;city&gt;Denver&lt;/city&gt;
          &lt;/address&gt;
      &lt;/addressList&gt;
      &lt;phoneContactList&gt;
          &lt;phoneContact&gt;
              &lt;primary&gt;234&lt;/primary&gt;
              &lt;cell&gt;4667&lt;/cell&gt;
          &lt;/phoneContact&gt;
          &lt;phoneContact&gt;
              &lt;primary&gt;5467&lt;/primary&gt;
              &lt;cell&gt;87904&lt;/cell&gt;
          &lt;/phoneContact&gt;
      &lt;/phoneContactList&gt;
      &lt;oneToOne&gt;
          &lt;firstField&gt;value&lt;/firstField&gt;
          &lt;secondField&gt;value&lt;/secondField&gt;
      &lt;/oneToOne&gt;
  &lt;/ProductType&gt;
  &lt;/ProductResultSet&gt;
  </code></pre>
  
  <p>The console spits out "Uncaught TypeError: Cannot call method 'indexOf' of undefined" for the RecordAddresses output, and then I get an object filled with arrays with 0 objects for the Associated Data output.</p>
  
  <p>I'm completely stumped on this one. I've searched around everywhere and it's taken me this far. Why is the record not loading the nested data in that xml file?</p>
  
  <p>Any help will be greatly appreciated.</p>