PDA

View Full Version : Created class has "" string value for belongsTo arrays



ipavlic
17 Oct 2012, 12:07 AM
This question is similar to http://www.sencha.com/forum/showthread.php?245817-Created-class-has-default-values-instead-of-undefined

(http://www.sencha.com/forum/showthread.php?245817-Created-class-has-default-values-instead-of-undefined)This time I'm interested why an array of children that belong to parent are initialized by an empty string instead of an empty Array or undefined. This breaks saving functionality as my server side expects an array, not a string.


Ext.define('MyApp.model.Parent', {
extend : 'Ext.data.Model',
hasMany : [ {
model : 'MyApp.model.Child',
name : 'children'
} ]
});



var parent = Ext.create('MyApp.model.Parent');
console.log(parent); //parent.data.children will be "" instead of 'undefined' or []

mitchellsimoens
22 Oct 2012, 9:01 AM
Associated data will no longer be in the data object of the main record. It will be saved as a store or model instance on the main record accessible by the getter.

ipavlic
22 Oct 2012, 10:44 PM
Associated data will no longer be in the data object of the main record. It will be saved as a store or model instance on the main record accessible by the getter.
I don't understand what you are trying to say. If I store the parent with

parent.save()
ExtJS will try to save the children as "". It doesn't matter what's in the data, or whether the data is used – I'd like my associated data to be saved as something which makes sense on parent.save(). Instead, it is saved as "" which does not make sense.