PDA

View Full Version : Adding models through association stores



KarlPurk
10 Sep 2013, 6:40 AM
Hi,

I'm trying to understand the correct approach for adding models to a store through an association. For example, I have two models, Site and Sample. Sites has many Samples and I have set up the association for this. I am creating a new Sample, and associating it to a Site, with the following "test" code:

Ext.getStore('Sites').getAt(0).samples().add({id: 1})

I can confirm that this model's store has been updated correctly by calling:

Ext.getStore('Sites').getAt(0).samples().getCount()
1

However the main samples store has not been updated:

Ext.getStore('Samples').getCount()
0

I assumed that the master store would be updated - that is, the model should have been added to both the master store and the model specific store. I also tried the other way around, I tried adding a new model to the master store but this was not pushed to the model store.

I feel like I'm either missing something, or that my approach is incorrect. I assumed the store on the model would be a subset of the master store and that the two were related? Do I manually need to sync the stores? Could somebody please offer some assistance.

I have based the approach on the information found here:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.association.HasMany

Thanks,

Karl

ettavolt
10 Sep 2013, 9:00 PM
Unfortunately, data package takes approach of "ActiveRecord" instead of "Object-Server Mapping".
So you should manually copy the resulting Sample to master store, or reload it. This can be somehow automated using listeners.