PDA

View Full Version : Id not being correctly created when using Store.loadData



Juanito
7 Apr 2011, 9:40 AM
I am loading data into a store using loadData. My JSON records all have an id property but when I use Store.indexOfId to find a record, I get -1 because the ids aren't what I expect them to be, they are Ext's generated IDs.

Here's a sample record array I'm passing into Store.loadData()

[
{"summary":"Philosophy professor Bill Ramseys feature Making The Grade: Why you may be wrong about whats right about chipping[No. 191] drew various comments from readers,...",
"id":1023,
"author":"admin",
"title":"The Chipping Contradiction",
"isHeadline":true,
"image":"/9j/4AAYH//Z"},
{"summary":"Ozturk on Meru in Nanda Devi National Park, in the Himalaya of northern India. Photo by Jimmy Chin. Renan Ozturk, leading climber and filmmaker, was involved...",
"id":1021,
"author":"Alison Osius",
"title":"Renan Ozturk seriously injured, but on upswing",
"isHeadline":false,
"image":"/9j/4AAQ3P/Z"}]


Here's my Model definition


Ext.regModel('ArticleListModel', {
fields: [
{name:'author',type: 'string'},
{name:'id',type: 'number'},
{name:'summary',type: 'string'},
{name:'image',type: 'string'},
{name:'title',type: 'string'}
{name:'isHeadline',type: 'boolean'}
]
});

When I look at one of the records, its internalId is ext-record-{number}. I thought I had a bug in my code somehwere but here's why I think it's Sencha's bug. When I call

store.findExact('id', this._article.articleId)
Everything works. However, if I call

store.indexOfId(this._article.articleId)
I get -1 back;

So I dug into the code:
Store.loadData calls Ext.ModelMgr.create(record, model) without passing in an ID which is expected by that method. Ext.ModelMgr.create ends up calling the Model constructor without an ID, therefore, giving it a made up ID.

dolittle
7 Apr 2011, 9:46 AM
This issue is related:
http://www.sencha.com/forum/showthread.php?128876-Store-is-currpoted-when-using-load

Does this help?
http://www.sencha.com/blog/ext-js-4-beta-2-released#19317

Do you think it also affects extjs 4?
Do they share the store code?

Juanito
7 Apr 2011, 4:05 PM
I do believe it's the same root cause. Ids not correctly set when using load data. In your case, you could try using the search methods that look up by field, and you specify the 'id' field, like I did.

dolittle
7 Apr 2011, 7:09 PM
It's not just that. Old records with the same id are still accessible.

The store is seriously broken.