PDA

View Full Version : direct store not updating record id after saving new record with 4.1.1a



bareflix
7 Jul 2013, 11:40 AM
I have an Ext.data.DirectStore connected to a grid and a form. When I create a new record, I call store.addSorted() which correctly triggers a create message. The reply from the create message is *exactly* the same as the reply from a read message, I've tripple checked this.
My data model has an "id" field, but the store is not updating the value of the record id with the record.

I added a listener to the store "write" event and when I print the newly created record, I see:

Object { phantom=false, internalId="ext-record-1", raw={...}, more...}
The data.id is = 0 in this case.

I tried adding idProperty to my model, but this made no difference.

Any suggestions on what else to try to debug this?

What extjs source file actually implements the id update? Is it in the model, proxy, store or ...?

slemmon
9 Jul 2013, 3:56 PM
That issue doesn't sound familiar to me. But, have you tried with the latest framework build: 4.2.1? There have been a number of bug fixes since the 4.1.1 release.

bareflix
12 Jul 2013, 6:20 AM
I see the same problem with 4.2.1.

Does it make a difference if I configure my proxy in the DirectStore or in my Model? Right now I'm configuring it in the Store.

What class processed the Direct response and sets the local record's new id? If I knew where to look I'm sure I could track this down, but so far I haven't been able to trace through all the events and callbacks that happen after you insert a new record in a store.

bareflix
12 Jul 2013, 10:22 AM
Ok, I tracked it down to the updateRecord function in data.Operations:


updateRecord: function(clientRec, serverRec) {
// if the client record is not a phantom, make sure the ids match before replacing the client data with server data.
if(serverRec && (clientRec.phantom || clientRec.getId() === serverRec.getId())) {
clientRec.copyFrom(serverRec);
}
},

for some reason clientRec.phantom is false at this point, even though it was definately true when I called store.addSorted ().

When I print the record after the directStore write finishes, I see:


Object { phantom=false, internalId="ext-record-1", raw={...}, more...}

which is clearly inconsistent. If I hack updateRecord and force phantom to true, it works correctly so this is the problem, but I don't have any idea where or why phantom is erroneously getting set to false.
Any ideas?

bareflix
12 Jul 2013, 10:43 AM
I finally tracked it down. I was calling:


store.addSorted(this.record);
this.record.commit ();

record.commit sets the phantom flag to false.
My comment about record commit said: "gets rid of the modified mark in the list and tells the store to save"

I guess that was needed in an older version of extjs, but is no needed in 4.1.1 and up.