PDA

View Full Version : getById fails after adding record to store



sgtpepper
27 Jun 2011, 3:34 PM
When we add a record to a store the value in the keys array for the store does not have a proper id. For example, when the store is first loaded the keys are this:

keys: Array (4)
0: "283"
1: "277"
2: "278"

When we add a record using add() and sync() with a rest store the id is returned from the database insert to the record in the store, but the keys array now looks like this:

keys: Array (4)
0: "283"
1: "277"
2: "278"
3: "ext-record-72"

The record in the data array correctly has the id from the database insert, but it is not correctly set in the keys array. Since getById() uses the keys array it is unable to find the newly added record.

Note that we had to modify sencha-touch.js by replacing:

data.replace(record);

...with this:

if (action == 'create') {
data.replace(data.getKey(this.getNewRecords()[0]), record);
}
else {
data.replace(record);
}

...to get the id from the database insert correctly added to the store.

lylepratt
31 Jul 2011, 12:13 PM
I can verify that this is indeed a bug.