PDA

View Full Version : [INFOREQ]Store returning all records for getNewRecords



mtycholaz
18 May 2011, 10:25 AM
I have a problem with a Model/Store. The store is set to autoload the records via a proxy. However once the records are loaded and store.getNewRecords() is called, all the records in the store are returned as new. This doesn't seem right. Also and records I update do not get returned when I call store.getUpdatedRecords().

Model


Ext.define('Daedalus.model.Group', {
extend: 'Ext.data.Model',
fields: [
{ name: 'Id', type: 'int', mapping: 'Id' },
{ name: 'Name', type: 'string', mapping: 'Name' }
]
});

Store


Ext.define('Daedalus.store.Groups', {
extend: 'Ext.data.Store',
model: 'Daedalus.model.Group',

autoLoad: false,

proxy: {
type: 'rest',
url: Daedalus.app.WcfUrl + '/groups',
reader: 'json'
}
});

Update record code


groupSave: function(button, event){
var blind = this.getBlind(button), view = this.getApplication(button), groupStore = Ext.data.StoreManager.lookup('Groups'), form = blind.items.items[0].getForm();

if(blind.mode == "create"){
var record = new Daedalus.model.Group();
form.updateRecord(record);
groupStore.add(record);
}
else{
form.updateRecord(form.getRecord());
}

blind.close();
}

Now when I try to sync the changes these arrays do not return what I expect.



//contains all the records. New and updated
var newRecords = groupStore.getNewRecords();

//doesn't contain any records
var updatedRecords = groupStore.getUpdatedRecords();

//all the records are sent to the server which is incorrect
groupStore.sync();


No clue what I'm doing wrong so any help is appreciated.

jsakalos
18 May 2011, 3:56 PM
This looks like a bug. Do you want me to move this thread to Bugs forum?

mtycholaz
19 May 2011, 10:32 AM
Yes please and thank you.

evant
19 May 2011, 10:29 PM
What does your data look like? A record is considered "new" if it's a phantom. That is, it doesn't have an id assigned to it from the server.

mtycholaz
20 May 2011, 6:54 AM
Here's the JSON output from the server.


[{"Id":3006,"Name":"OYDKTENZ","Permissions":null},{"Id":3007,"Name":"TAUATGKO","Permissions":null},{"Id":3008,"Name":"MKEVEFTP","Permissions":null},{"Id":3009,"Name":"RNVLEHQD","Permissions":null},{"Id":3010,"Name":"WPNBEKNS","Permissions":null},{"Id":3011,"Name":"BSEREMKG","Permissions":null},{"Id":3012,"Name":"GUVHEOHU","Permissions":null},{"Id":3013,"Name":"ZEFDQOQW","Permissions":null},{"Id":3014,"Name":"EHWTQQNK","Permissions":null},{"Id":3015,"Name":"JJOJQSLZ","Permissions":null}]

This data is loaded via the store proxy.

mtycholaz
20 May 2011, 8:17 AM
Managed to find out what the issue was. The default idProperty is "id" not "Id". All that had to be done was to set the idProperty of the JSON reader and everything works as expected. Now this is just my personal opinion, but wouldn't setting the field on a model as a "PrimaryKey" make more sense than on the reader itself?