1

I have two Models. Master -

Ext.define('App.model.Master', {
   extend    : 'Ext.data.Model'

  ,fields    : [
    { name  : 'master_name', type  : 'string' },
    { name  : 'id', type  : 'int'}
  ]
  ,proxy    : {
    type  : 'rest',
    url    : '/master',
    reader    : {
      type  : 'json',
      root  : 'masters'
    }
  }
  ,associations  : [{
    type      : 'hasMany'
    id        : 'id',
    foreignKey    : 'master_id',
    associationKey  : 'details',
    name      : 'details',
    model      : 'App.model.Detail',
  }]
});

and Detail -

Ext.define('App.model.Detail', {
  extend    : 'Ext.data.Model'
  fields    : [
    { name  : 'detail_name', type  : 'string' },
    { name  : 'id', type  : 'int' },
    {name  : 'master_id', type  : 'string'}
  ]
});

My problem is, when I add a new Master record, there is a Detail that is added automatically in the Server. And the response that I get is -

{
  success : true,
  masters : {
    master_name  : 'aaa',
    id      : 1,
    details    : [
      {
        detail_name  : 'bbb',
        id      : 11,
        master_id  : 1
      }
    ]
  }
}

Despite all my efforts, I'm not able to read the 'detail', once the response is added into the Master Store. I would think that the 'record.details()' would give me the one record that came back on adding of the Master, but I get nothing.

However, if I reload the store, I'm able to get the data correctly.

I need to be able to read the nested response on Store.add() as well.

Any help is much appreciated.

abhijit
  • 6,363
  • 5
  • 26
  • 32
  • I'm just wondering... the root of your reader is `masters`, but it does not seem to be part of the JSON that the server returns. Have you simply omitted that? – Izhaki Dec 11 '12 at 22:48
  • I've updated the response to show the complete response object – abhijit Dec 12 '12 at 05:09
  • Maybe a silly question, but do you define detail before master in your javascript file? – Reimius Dec 17 '12 at 17:39
  • possible duplicate of [ExtJS 4.1 - Returning Associated Data in Model.Save() Response](http://stackoverflow.com/questions/18281513/extjs-4-1-returning-associated-data-in-model-save-response) – Dave Jan 15 '14 at 05:31

0 Answers0