View Full Version : DataReader realize usage

9 Sep 2009, 10:27 PM
I'm trying to realize a record created with a dummy id, with data returned from the server. But after calling realize on the DataReader I can't find the record by calling getById on the store using the new Id...

// DWR create callback
callback :function(data, args) {
var newBookingObj = Ext.decode(data);
g.bookingStore.reader.realize([args.booking], [newBookingObj]);
// g.bookingStore.getById(newBookingObj.Id) === null
arg: {
booking : r

Any hints?

10 Sep 2009, 1:02 AM
The id property of a Record is lowercase.

10 Sep 2009, 1:06 AM
I know, but that's not relevant here. My reader is configured with idProperty: 'Id'. and the server sends back a blob with Id property set properly...

newBookingObj is the decoded blob and newBookingObj.Id is a valid Id

Examining the record shows it has updated its id to my newBookingObj.Id which is good. I feel like the store is not aware of this change/realization...

10 Sep 2009, 2:15 AM
I'm not really familiar with that area. All I can suggest is step into the realize call and see what happens to the Record.

10 Sep 2009, 3:05 AM
WTF??? Something I never thought I'd see in an Animal post.

I'm not really familiar with that area.


10 Sep 2009, 3:06 AM
If the records are part of a store you also need to reMap them.

10 Sep 2009, 3:07 AM
How do I do that..? :">

10 Sep 2009, 3:16 AM
g.bookingStore.reader.realize(args.booking, newBookingObj);

ps. realize and reMap support both arrays or single objects.

10 Sep 2009, 3:25 AM
Thanks Condor. I searched for reMap but didn't find anything anywhere in the docs. Is it a private method or just not documented? Would it make sense for the record to notify its store about the realization to be able to use store.getById right after a realize?

10 Sep 2009, 3:26 AM
That method is not documented. Anyone want to volunteer some documentation for it? I couldn't describe its purpose properly - I'm not familiar enough with it.

10 Sep 2009, 3:28 AM
I'm not familiar enough with it.

Stop using that phrase, it doesn't suit you :)

10 Sep 2009, 3:35 AM
It's not a method for public use, it should be left private.

ps. I would recommend calling store.onCreateRecords, so you don't have to call realize and reMap yourself.
Or maybe even create a DWRProxy, so you don't have to worry about realize and reMap at all.

10 Sep 2009, 3:54 AM
Sounds like a good idea. But how would I solve this if I weren't using DWR and instead just used a DataWriter for example, would this realization and remap be handled internally already by the record/store? Just curious....

10 Sep 2009, 4:15 AM
Yes, this is already automatically handled by the callback of a 'create' action.

(that is why I recommended creating a DWRProxy instead of trying to do this yourself)