PDA

View Full Version : [OPEN]Adding a record with the same ID does not remove stale or duplicate records



jlmorgan
1 Mar 2011, 8:18 AM
Fields in Model:

['id', 'name']

Initial data:

[
['1', 'Text 1'],
['2', 'Text 2']
]


store.load(); // Pull in the above records

New data gets written and we just want to update the store, but not load everything again

New data:

[
['1', 'Text A']
]

store.load({ addRecords: true });

Resulting data:

[
['1', 'Text 1'],
['2', 'Text 2'],
['1', 'Text A']
]

Even though the id should be unique, it's allowing duplicates. The second '1' should overwrite or cause the other instances to be removed resulting in (ideally):


[
['1', 'Text A'],
['2', 'Text 2']
]

This is not a situation where there is an intelligent source behind the data and it is loading two static sets of data in the attempt to merge the two and have a single resulting set. It's just the nature of the problem and cannot be avoided. As a result, the aforementioned issue arises.

evant
1 Mar 2011, 10:47 PM
You haven't provided enough information. What does your full model look like? Specifically, how are you setting the identifier?

jlmorgan
2 Mar 2011, 5:51 AM
src/Ext.data.Model



/**
* @cfg {String} idProperty The name of the field treated as this Model's unique id (defaults to 'id').
*/
idProperty: 'id',


Aside from that, nothing as far as I know, is remotely important.

Condor
2 Mar 2011, 8:07 AM
I completely agree.

The Ext.data.Store.prototype.loadRecords method (with parameter add = true) adds all records instead of adding/updating them like Ext 3.3 does.

Currently you get the Ext 3.2 (and earlier) behavior.

evant
2 Mar 2011, 1:35 PM
Ah right. I remember now, in fact I think I added the fix in the 3.x branch!

Will look into it.