PDA

View Full Version : HasManyAssociation automatic store-creating function not present?



adisharoon
4 Nov 2011, 1:44 PM
I have an MVC application with two models. One (client) has many of the other (environments). The actual data is returned by JSON that looks like this:



{"environmentsByClient": [{"client": "ONE", "environments": [{"window": "12:00", "type": "MM", "name": "ONE-MM"}, {"window": "1:00", "type": "NN", "name": "ONE-NN"}]},{"client": "TWO", "environments": [{"window": "12:00", "type": "MM", "name": "TWO-MM"}, {"window": "1:00", "type": "NN", "name": "TWO-NN"}]}]}

The other code is (these are actually separate files that are referenced in the applications 'models' config option):


Ext.define("sqlDeploy.model.clientModel", {
extend: "Ext.data.Model",
fields: [
{
name: "client",
type: "string"
},
],
proxy: {
type: "ajax",
url: "getEnvironments",
reader: {
type: "json",
root: "environmentsByClient"
},
pageParam: undefined,
startParam: undefined,
limitParam: undefined
},
hasMany: {
model: "environmentModel",
name: "environments"
}
}
);

Ext.define("sqlDeploy.model.environmentModel", {
extend: "Ext.data.Model",
fields: [
{
name: "name",
type: "string"
},
{
name: "type",
type: "string",
},
{
name: "window",
type: "time"
}
],
belongsTo: {
model: "clientModel",
name: "client"
}
}
)



My question, then, is why doesn't something like this work:


var store = Ext.create("Ext.data.Store", {
model: "sqlDeploy.model.clientModel"
});


store.load({
callback: function(){
console.log(store.first().environments());
}
});


I get "store.first().environments is not a function".

That last bit is a simplification - I'm actually using these in a couple of dependent combo boxes.

Alec

adisharoon
4 Nov 2011, 1:56 PM
Using the full name of the other model class, like this:

hasMany: {
model: "sqlDeploy.model.environmentModel",
name: "environments"
}

in addition to noticing that the "select" event on ComboBox returns an array of records, instead of just the selected record. solved the problem