PDA

View Full Version : How to update record?



dbassett74
12 Oct 2009, 5:37 AM
I'm not clear how to do this reading the docs, but how do I update a single record in a store with a completely new copy of a record? In other words, I don't want to loop through all the fields of the record and update individually, rather, I want to take a completely new record apply the whole thing at once to a particular record in a store. Any help would be appreciated.

Condor
12 Oct 2009, 5:45 AM
You could use:

record1.beginEdit();
record1.data = record2.data;
record1.markDirty();
record1.endEdit();
but:
1. This won't change the record id (for that you will have to remove the old and add the new record).
2. Assumes all fields have changed (otherwise you will have to loop through all fields).

dbassett74
12 Oct 2009, 6:23 AM
It will use the same ID, but not all fields will necessarily be changed, so I guess looping through each field is not all that big of deal. Thanks!

Mike Robinson
12 Oct 2009, 9:23 AM
(1) Within a "BeginEdit/EndEdit" block, update all field-values except the ID.
(2) Associate a properly-defined "writer" object with the Store to automagically submit the changes to the host.
(3) Remember, as always, that the update-process is asynchronous. At the time you finish your local updates, the host emphatically has-not even received your update-request, let alone carried it out.