PDA

View Full Version : [FIXED] Unable to set "idProperty" of Model



jeroenvduffelen
28 Jun 2010, 2:28 AM
Ext.regModel('book', {
idProperty: 'bookId',
fields: [
{name: 'bookId', type: 'string', defaultValue: 'grmbl..'},
{name: 'bookTitle', type: 'string'},
],
});


Doesn't seem to give the wanted result... I expect when setting idProperty that my new instances id becomes the value of bookId. But it's stays the default: "ext-record-1", "ext-record-2", "ext-record-3", etc etc

edspencer
28 Jun 2010, 11:31 AM
The .id property is an internal ID we use to track model instances that have never been saved and therefore do not have a bookId yet. In the next beta I'll change this to something more meaningful like .internalId to avoid this confusion. For now you can use the API as documented - getId() and setId(), which do honor the idProperty.

jeroenvduffelen
28 Jun 2010, 11:48 AM
never mind, after reading your reply for the second time i got it!

jeroenvduffelen
28 Jun 2010, 12:21 PM
ok... back again :)

When trying to do the next thing:


datastoreBooks.getById(bookId)

It gives me undefined. Probably because this searches for that internal ID. So it's a bit confusing how it all works with that ID.

TommyMaintz
29 Jun 2010, 2:24 PM
idProperty in Ext JS makes it so that the internalId is mapped to that property. That way you can use getById etc using your own id's instead of generated ones. Expect this to be the same for Sencha Touch in the next release (due in a couple hours).

edspencer
29 Jun 2010, 2:54 PM
As of the next release, Store#getById will honor the configured idProperty of the model, not the private internal ID we assign to every model instance.

profunctional
8 Feb 2011, 1:20 PM
What is the trick to getting this to work? I set the idProperty of my model to ID. Then I try to use store.getById(ID) and it always returns null. What else is needed for this to work.

edspencer
8 Feb 2011, 1:31 PM
What is the trick to getting this to work? I set the idProperty of my model to ID. Then I try to use store.getById(ID) and it always returns null. What else is needed for this to work.

That should be all you need. If you can provide a small but complete code sample showing the problem I'll be happy to help

edspencer
8 Feb 2011, 1:31 PM
What is the trick to getting this to work? I set the idProperty of my model to ID. Then I try to use store.getById(ID) and it always returns null. What else is needed for this to work.

That should be all you need. If you can provide a small but complete code sample showing the problem I'll be happy to help