Hi,
I am trying to use the HasMany Association between to models. I can load it fine but I can't save new associations using a REST proxy.
I have the models Substance and SubstanceGroup. A substance group contains many substances and a substance may be used in several groups.
I've got one REST resources substance for the substances and another REST resource substance_group for the substance groups.
My current model classes look like:
Code:
Ext.define('substance_groups.model.Substance', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{
name: 'id',
type: 'string'
},
{
name: 'name'
}
],
proxy: {
type: 'rest',
url: '../../../../../api/substance'
}
});
Ext.define('substance_groups.model.SubstanceGroup', {
extend: 'Ext.data.Model',
requires: [
'substance_groups.model.Substance'
],
uses: [
'substance_groups.model.Substance'
],
idProperty: 'id',
fields: [
{
name: 'id'
},
{
name: 'name',
type: 'string'
}
],
hasMany: {
model: 'substance_groups.model.Substance',
autoLoad: true,
name: 'substances'
},
proxy: {
type: 'rest',
url: '../../../../../api/substance_group'
}
});
When I add substances to a group using the store group.substances() it is displayed fine. Yet when I save it no substances are transferred.
What I would like to see is something like:
Code:
POST api/substance_group
{
id: '242',
name: 'My Group',
substances: [
{
substance_id: '123'
},
{
substance_id: '456'
}
]
}
Any hints on how to do that? Help very much appreciated!!