PDA

View Full Version : Ext.data.Store.save() send "create" records in reverse order.



nbabinski
2 Dec 2011, 9:32 AM
Ext version: 3.4.0

Description: Ext.data.Store.save() method sends records to be created Ext.data.Api.actions.create in reverse order.

Ext.data.Store.save() method:


save : function() {
...
if(rs.length){
// CREATE: Next check for phantoms within rs. splice-off and execute create.
var phantoms = [];
for(i = rs.length-1; i >= 0; i--){ //the cause
if(rs[i].phantom === true){
var rec = rs.splice(i, 1).shift();
if(rec.isValid()){
phantoms.push(rec);
}
}else if(!rs[i].isValid()){ // <-- while we're here, splice-off any !isValid real records
rs.splice(i,1);
}
}
// If we have valid phantoms, create them...
if(phantoms.length){
queue.push(['create', phantoms]);
}


// UPDATE: And finally, if we're still here after splicing-off phantoms and !isValid real records, update the rest...
if(rs.length){
queue.push(['update', rs]);
}
}
...
};


Possible fix:




save : function() {
...
if(rs.length){
// CREATE: Next check for phantoms within rs. splice-off and execute create.
var phantoms = [];
for (i = 0; i < rs.length; i++) {
if(rs[i].phantom === true){
var rec = rs.splice(i, 1).shift();
i--; //index correction after removal
if(rec.isValid()){
phantoms.push(rec);
}
}else if(!rs[i].isValid()){ // <-- while we're here, splice-off any !isValid real records
rs.splice(i,1);
i--;
}
}
// If we have valid phantoms, create them...
if(phantoms.length){
queue.push(['create', phantoms]);
}


// UPDATE: And finally, if we're still here after splicing-off phantoms and !isValid real records, update the rest...
if(rs.length){
queue.push(['update', rs]);
}
}
...
};

mitchellsimoens
2 Dec 2011, 11:28 AM
Thank you for the report. Only severe bugs will be fixed in Ext JS 3 if there are any found. Otherwise development is on Ext JS 4.