PDA

View Full Version : [CLOSED] [1.1.0] idProperty of Model is ignored



RoyW
19 Aug 2011, 8:20 AM
I have tested in Chrome & Firefox.

Run the following code. The second store does not get id's so store.loadData (http://dev.sencha.com/deploy/touch/docs/source/Store.html#method-Ext.data.Store-loadData)( Array data, Boolean append )
will always append data to the store

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Id Property Bug</title>

<!-- Sencha Touch CSS -->
<link rel="stylesheet" href="http://dev.sencha.com/deploy/touch/resources/css/sencha-touch.css" type="text/css">

<!-- Sencha Touch JS -->
<script type="text/javascript" src="http://dev.sencha.com/deploy/touch/sencha-touch.js"></script>


<script type="text/javascript">

Ext.regModel('DataRecordModel1', {
idProperty: 'id',
proxy : {
type: 'memory'
},

fields : [
{name: 'id', mapping: 'id'},
{name: 'userName', mapping: 'name'},
{name: 'age', mapping: 'age'}
]
});

Ext.regModel('DataRecordModel2', {
idProperty: 'identifier',
proxy : {
type: 'memory'
},

fields : [
{name: 'id', mapping: 'identifier'},
{name: 'userName', mapping: 'name'},
{name: 'age', mapping: 'age'}
]
});


Ext.onReady(function(){

var store1 = new Ext.data.Store({
model: 'DataRecordModel1',
data: [
{ "id" : 1, "name": "Fred", "age" : 50},
{ "id" : 2, "name": "Joe", "age" : 50},
{ "id" : 3, "name": "Sam", "age" : 50}
]
});
console.log("Store 1", store1.getCount());
store1.each(function(rec){
console.log(rec.get('id'), rec.getId());
});

var store2 = new Ext.data.Store({
model: 'DataRecordModel2',
data: [
{ "identifier" : 5, "name": "Fred", "age" : 50},
{ "identifier" : 6, "name": "Joe", "age" : 50},
{ "identifier" : 7, "name": "Sam", "age" : 50},
{ "identifier" : 8, "name": "Bob", "age" : 50}
]
});

console.log("Store 2", store2.getCount());
store2.each(function(rec){
console.log(rec.get('id'), rec.getId());
});


});

</script>
</head>
<body></body>
</html>

mike.estes
19 Aug 2011, 11:24 AM
I don't see any bug here.

The source of getId:



getId: function() {
return this.get(this.idProperty);
}


Your example code is using the field mapping to map 'identifier' to 'id' so your record ends up with an 'id' field, not an 'identifier' field.

If you comment out the idProperty, all works as expected.

RoyW
19 Aug 2011, 11:53 AM
For some reason I thought the idProperty referred to the JSON data not the converted data