View Full Version : Request: Don't give new records "valid" IDs
cwolves
8 Jun 2007, 4:19 AM
When new records are added to a store they are automatically given ID #s starting at 1,000. Could this be changed in some way? It seems rather dangerous and the first time I made a grid I ran several deletes against my database on id=1002 or whatnot. Fortunately it's a new database so that ID doesn't exist, but you get the point.
Maybe start at -1 and decrement? Do the rows -have- to have an id at all?
jack.slocum
8 Jun 2007, 4:44 AM
If you don't tell it where to get an id, it will need to create one. You don't have to use that id if you don't want it, but an id is needed internally.
cwolves
8 Jun 2007, 5:08 AM
That's fine, I'm just saying that it's dangerous to use potentially valid ID numbers. Would there be any issues making them all negative?
When I'm adding new records I don't actually have a valid id to assign to the record since it doesn't exist yet in the database. I've ended up assigning all new records an id of "new" which works fine for me, but reading the modified records after adding a record and getting one with an id of 1002 is very dangerous in my opinion since many people are going to be using that id to update a database row.
Animal
8 Jun 2007, 5:23 AM
Could there be some way of specifying your own id generator, so that you can generate ids which "look" different for new records?
Animal
8 Jun 2007, 5:25 AM
Ext.data.Record = function(data, id){
this.id = (typeof id == "function") ? id() : ((id || id === 0) ? id : ++Ext.data.Record.AUTO_ID);
this.data = data;
};
?
Animal
8 Jun 2007, 5:31 AM
It's the Reader which passes this, so it's that which has to do the above code....
So instead of
var myReader = new Ext.data.XmlReader({
totalRecords: "results", // The element which contains the total dataset size (optional)
record: "row", // The repeated element which contains row information
id: "id" // The element within the row that provides an ID for the record (optional)
}, RecordDef);
You could
var myReader = new Ext.data.XmlReader({
totalRecords: "results", // The element which contains the total dataset size (optional)
record: "row", // The repeated element which contains row information
id: myIdGenerator // My id generation function
}, RecordDef);
That would mean in XmlReader
var id = (typeof sid == "function") ? sid() : sid ? q.selectValue(sid, n) : undefined;
Animal
8 Jun 2007, 5:33 AM
JsonReader attempts to generate a function usnig it's meta.id anyway, so it could just not bother, and set this.getId to meta.id if meta.id was a function...
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.