Last Updated: February 25, 2016
·
1.372K
· rodnaph

ExtJS 4 belongsTo Association

I could well just be dumb, but it seems associations in ExtJS 4 are broken. Following the documentation will only lead to confusion and wasted time. So, after much step-through debugging of the Ext source here's the minimal config that allows me to turn some JSON like this...

{
  success: true,
  items: [
    {
      id: 1,
      relation: { id: 1, name: 'Relation' }
    }
  ]
}

Into actually parsed models...

Ext.define('App.data.MyModel', {
  extend: 'Ext.data.Model',
  associations: [
    {
      type: 'belongsTo',
      model: 'App.data.MyRelation',
      associationName: 'relation',
      getterName: 'getRelation'
    }
  ]
}

Then go define your App.data.MyRelation model too obv. Phew...