PDA

View Full Version : HasMany Association not saved by REST proxy



28 Jan 2013, 4:37 AM
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:


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:


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!!

mitchellsimoens
30 Jan 2013, 10:34 AM
I don't believe store syncing work with associations, least last I tried while back.

30 Jan 2013, 11:09 AM
Ok thanks. I thought so too and started building the JSON manually which is fine.