PDA

View Full Version : [OPEN-1367] Writer incorrectly merges server result



michael@freepascal.org
26 Oct 2010, 6:48 AM
The documentation states that
"You must return at least the database pk using the idProperty defined in your DataReader configuration. The incoming data from server will be merged with the data in the local record."

My server application returns just that:
[{IS_ID: 127}]
but the data is not merged. The realize method in the store/reader simply replaces the data in the record with the data returned by the server, as can be seen in the realize() method:
rs.phantom = false; // <-- That's what it's all about
rs._phid = rs.id; // <-- copy phantom-id -> _phid, so we can remap in Store#onCreateRecords
rs.id = this.getId(data);
rs.data = data;

The data comes from the JSONReader extractData, which in turn calls extractvalues:

extractValues : function(data, items, len) {
var f, values = {};
for(var j = 0; j < len; j++){
f = items[j];
var v = this.ef[j](data);
values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue, data);
}

return values;
}

All fields are present in 'data': either the value of the server, or the default value for the field.

Thus, unless the server returns values for ALL fields, the returned data will not get merged correctly, but will simply replace the current data.

Post data:
rows {"IS_CODE":"ABC","IS_NAAMGEBRUIKER":"DEF","IS_KLEUR":"123","IS_LOGO":"","IS_LIVEDOMAIN":"mydomain","IS_SCHOOL_FK":"1209"}
Return data:
[{IS_ID: 127}]
IS_ID is the value of the 'idProperty' configuration.
The end result in the store is
{"IS_ID": 127 "IS_CODE":"","IS_NAAMGEBRUIKER":"","IS_KLEUR":"","IS_LOGO":"","IS_LIVEDOMAIN":"","IS_SCHOOL_FK":""}

Where the expected result is
{"IS_ID": 127, "IS_CODE":"ABC","IS_NAAMGEBRUIKER":"DEF","IS_KLEUR":"123","IS_LOGO":"","IS_LIVEDOMAIN":"mydomain","IS_SCHOOL_FK":"1209"}

I have attached a test project that demonstrates the bug.
grid is loaded with (dummy) data,
add button adds a new record.
Record can be edited in the grid
As soon as 'Save' is pressed, the record values disappear.

michael@freepascal.org
27 Oct 2010, 2:16 AM
Ext version tested:


Ext 3.2.1 rev ____



Adapter used:


ext



css used:


only default ext-all.css





Browser versions tested against:


FF3 (firebug 1.4.5 installed)



Operating System:


Linux



Description:


Documentation states that when a Ext.data.JsonWriter posts records to the server, the response from the server is merged with the local record. Instead, the data received from the server overwrites the record.



Test Case:

See testproject attached to first post.

Steps to reproduce the problem:


Open page. Data is loaded.
Press add. A new record is made
Optionally edit record.
Press 'save'
record values disappear.



The result that was expected:


Record values remain as is.
Primary key returned from server is merged in existing record.



The result that occurs instead:


Record contains only primary key, all other values are deleted.



Debugging already done:


See ExtJS code posted in first post.