I'm using ExtJS 4.0.7 with the ExtJS MVC features. I have a parent model which hasMany
children which belongsTo
the parent.
What is the correct way to access the children? If I go through parent.children().data.items[0].data
(as opposed to parent.data.children[0]
), there is an unwanted property MyApp.model.parent_id
. I've also noticed differences between how the dates are stored.
First, here is the definition of the parent. So a parent will have many children.
Ext.define('MyApp.model.Parent', {
extend : 'Ext.data.Model',
fields : [ 'id' ],
hasMany : [ {
model : 'MyApp.model.Child',
name : 'children'
}],
proxy : {
type : 'direct',
api : {
create : Parents.create,
read : Parents.read,
update : Parents.update,
destroy : Parents.destroy
}
}
});
And each child will belong to a parent.
Ext.define('MyApp.model.Child', {
extend : 'Ext.data.Model',
fields : [ 'id', {
name : 'validFrom',
type : 'date',
dateFormat : 'time'
} ],
belongsTo : 'Parent'
});
I load a parent in my controller:
this.getParentModel().load(id, {
scope : this,
success : function(parent) {
// the party looks good here when logged to console
console.log(parent);
this.updateStore(parent);
}
});
When inspecting the parent in the console, this is what I find:
console.log(parent.data.children[0])
:
Console output:
Object
id: 3
validFrom: -1767225600000
__proto__: Object
console.log(parent.children().data.items[0].data)
:
Console output:
Object
id: 3
MyApp.model.parent_id: 209 // why is that here?
validFrom: Thu Jan 01 1914 01:00:00 GMT+0100 (Central European Standard Time)
__proto__: Object