Let’s say I have a model called Vehicle
Ext.define('AM.model.Vehicle', {
extend: 'Ext.data.Model',
fields: [
{name: 'brandId', type: 'int'},
{name: 'brandName', type: 'string'},
{name: 'modelId', type: 'int'},
{name: 'modelName', type: 'string'},
{name: 'yearOfRelease', type: 'int'}
]
});
As you can see, the vehicle model has fields “brandId”, “brandName”, etc.
For example, I want to edit an instance of this model.
I create an edit form, which has combobox linked to ‘brandId’ field.
Then I save the form values to a model instance with this
values = form.getValues();
record.set(values);
It all works fine, but there is a problem with all the fields that represent some outer models:
only id’s are updated, while all other fields, that depend on id remain the same.
In a regular OOP language(Java for example), I would create a class CarBrand
and put an instance of this class inside the Vehicle class.
In ExtJs 4 they have hasMany relationship, but don’t have hasOne.
What is the best approach in ExtJS 4 for such nested models?
4.0.* doesn’t support the hasOne relationship. 4.1 is meant to support it.
for 4.0.7 I have the following override in place.
Whats this lets me do is in my forms I create them with names like so.
Notice the . in the name field which lets the overridden setValues and updateRecord form know it needs to map these values to the new model, which is defined in the model like so.