View Full Version : Cannot sync store with hasmany association

14 Jan 2014, 11:15 PM

I am coding with ExtJS 4.2
I have Three models:

Consider a hypothetical hierarchy like:
Top level:
1.model : Family
attributes: Family Name
hasMany: Family Member : persist True

2.model: Family member
attribute: member Name
hasMany : Child : persist : True

3. model: Child
attribute : ChildName
attribute : childAttributes : type : auto

I have a store which loads data with model:Family.
This data is rendered in form and is edited.
Now i want to sync data by store.sync() back to my service.

Store only call sync() if the record in the top most model:Family is changed.
ie if i update a record of a Child for say Child's name, Top store/model is unaware of the lower level associated on the fly created stores - Family member & Child.

Although when i inspect my Child/Family member store just before the sync it shows me the updated value.
but the top most store in the hierarchy is unaware of the updates in the lower level stores.
I called getModifiedRecords() on the lower most Child store which returns me the modified record but the Top most store Family returns empty[].

I am using hasMany associations .. i have tried adding BelongTo as well but that doesn't help.

I think this thread presents the same problem in ST2.
a (http://www.sencha.com/forum/showthread.php?205430-Cannot-sync-store-with-hasmany-association)s i think stores/models work the same way in ST and ExtJS.

Am i missing some config in the lower associated models ?

Can this be a bug ?

please help.


15 Jan 2014, 12:53 AM

Unfortunately Sencha doesn't work well with associations. It does descent job loading them in one go (with a structured package from the server), but cannot save them back. In previous apps we implemented 2 workarounds:
1) called sync for child stores for associations, but this way you need to configure them properly so they know where to save their data
2) implemented mechanism for saving all in one go, but it was tough challenge

The problem is that Sencha's model knows that one of it's property may be an association and creates store for it, but it doesn't watch it.

15 Jan 2014, 1:30 AM

Ofcourse i dont want to make the Family member keep a reference to which Family model it belongs to .

Otherwise i would have read "raw" data and created my own stores to manage everything :(

I used associations to let the stores do everything out of the box so
form.loadRecord() loads the data..
form.updateRecord() will update the records
and the store can peacefully sync back the changed data !!!

Anyone .. any idea about this ?

Is it not at all possible to Sync data from the on-the-fly created stores using association models ?

Please Help

16 Jan 2014, 3:31 AM
~~BUMP ..

Please help.


17 Jan 2014, 5:23 AM


20 Jan 2014, 6:06 AM

please Help.


21 Jan 2014, 5:31 AM
~~ Bump please helpGV

21 Jan 2014, 5:09 PM
I think I have the same problem. Researching ...

21 Jan 2014, 6:18 PM
I have question which hasMany answers association. When I do question.answers().sync(); the correct data is sent and successfully processed by server, then correct response is sent back to client, but question.answers() store data is not correctly applied. I solved my problem by reloading question.answers() manually.

answer.set('someField', someValue);
}, this);

success: function(batch, options) {
// force answers reload
params: {
questionId: question.get('id')
failure: function(batch, options) {
// handle failure
scope: this

23 Jan 2014, 12:34 AM
waiting for answer