Answer the question
In order to leave comments, you need to log in
ExtJS New model, save and hasMany connection
Good afternoon.
There was a problem with models and relationships. There is a pattern like this:
Ext.define('App.model.Server', {
extend: 'Ext.data.Model',
fields: [...],
hasMany: [
{
name: 'ports',
model: 'App.model.Port',
foreignKey: 'server_id',
associationKey: 'ports'
}
]
});
Ext.define('App.model.Port', {
extend: 'Ext.data.Model',
fields: [
'server_id',
...
]
});
Answer the question
In order to leave comments, you need to log in
There was no time to answer my own question, but here is the solution that was applied:
https://gist.github.com/yuristrelets/9b543be8cd8af... Let me
explain a little:
The “original” method code was copied into copyFrom, although callParent could have been called , but then you would have to repeat all the checks again.
The updateHasManyAssociations method code is quite simple, it takes a single argument - the id of the new model.
Here we go through all the associations of the model, but we “react” only to the hasMany type. Next, we update the field with the foreign key (stored in the foreignKey variable) for all records of the related store. This is necessary for records that are already in the store.
In order for the foreign key to be set automatically for records that will be added later, we look for the modelDefaults property of the store and update the property with the name of the foreign key in it. The modelDefaults object stores all the default values for the added models and is used in the insert method of the store.
Well, the last step is to update the filter value for the associated store, this may come in handy for its further reload.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question