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

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,...",
"title":"The Chipping Contradiction",
{"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...",
"author":"Alison Osius",
"title":"Renan Ozturk seriously injured, but on upswing",

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

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.

7 Apr 2011, 9:46 AM
This issue is related:

Does this help?

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

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.

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.