Thursday, 21 August 2014

ExtJS4: Missing HasOneInstance While Decoding JSON

Sometime ExtJS plays dumb role in throwing exceptions. It ignores exceptions instead of handling them, especially while dealing with associations. 

Whenever ExtJs loads data throw proxy into model, it decodes json data into respective models including associations. In case of hasMany association it creates <association-name>Store and in case of hasOne association, it creates <association-name>HasOneInstance store and decodes data into corresponding stores. 

But here are some cases where ExtJS may miss these conversions without throwing any error. 
  • If your association name is in camel case and if you have defined its association with its basic properties like type and model, then ExtJs generates rest of the properties by default. While generating default properties it converts camel case text into lower case and associate it to the association. 
   For example if you have defined a hasOne association as follows, 
       associations: [{ type: 'hasOne', model: 'homeAddress' }]
  It generates association_key as homeaddress (converts camel case into lower case) and maps this key      with the json object which will be in camel case. Because of mismatch in name, it doesn't create homeAddressHasOneInstance object in the parent object. 
  • If you don't use association's model explicitly and miss its inclusion in controller then ExtJS doesn't complain about the model and store conversion will not happen for that association. 

No comments:

Post a Comment