The SmartClient documentation and http://forums.smartclient.com/showthread.php?t=6333, comment #4 says: "If you're changing the primaryKey, do a remove then add."
But I found a trivial solution which works (at least for me) without problems.
The change is in file ResultSet.js, method updateCacheData():
I also attached the complete source code of updateCacheData() method.
Borut
But I found a trivial solution which works (at least for me) without problems.
The change is in file ResultSet.js, method updateCacheData():
Code:
...
// if we didn't find the record in our cache, check for the case where the server
// returned a changed (bad) primary key value for an update of an existing record.
// In this case warn, and clear out the original version of the record.
if (index == -1) {
var submittedRecord = dsRequest.data;
if (isc.isAn.Array(submittedRecord)) submittedRecord = submittedRecord[0];
// pare down to PKs and find in our data-set
submittedRecord = isc.applyMask(submittedRecord, keyColumns);
var oldRecordIndex = this.getDataSource().findByKeys(submittedRecord, cache);
if (oldRecordIndex != -1) {
this.logWarn("Update operation - submitted record with primary key value[s]:" +
this.echo(submittedRecord) + " returned with modified primary key:" +
this.echo(keyValues) + ". This may indicate bad server logic. " + "Updating cache to reflect new primary key.");
// remove the old record from our dataSet. If it matches filter, we'll re-add below
removedRows++;
cache.removeAt(oldRecordIndex);
// this is a weird case - don't attempt to fire row-specific dataChanged
delete this._lastUpdateData;
}
// <==== changes to handle modification of the primary key ====
else {
submittedRecord = dsRequest.oldValues;
if (submittedRecord) {
submittedRecord = isc.applyMask(submittedRecord, keyColumns);
var oldRecordIndex = this.getDataSource().findByKeys(submittedRecord, cache);
if (oldRecordIndex != -1) {
this.logWarn("Update operation - submitted record with old primary key value[s]:" +
this.echo(submittedRecord) + " returned with new primary key:" +
this.echo(keyValues) + "Updating cache to reflect new primary key.");
// remove the old record from our dataSet. If it matches filter, we'll re-add below
removedRows++;
cache.removeAt(oldRecordIndex);
// this is a weird case - don't attempt to fire row-specific dataChanged
delete this._lastUpdateData;
}
}
}
// ==== end of changes to handle modification of the primary key ====>
} else if (updateData.length == 1) {
origRecord = cache.get(index);
// catch the case where the orig record is present in the allRows cache but doesn't
// match filter criteria for local data
if (filteringOnClient &&
...
Borut
Comment