You can't 'set' a primary key on a model with Extjs. The concept itself does not exist in the library. The ID of the record needs to be unique, but there is really nothing that enforces it to be so. My question for you is, what do you even want done when a duplicate record is added? Do you want the values of the record to overwrite based on the key? Do you want an exception?
The best suggestion I can have for you is to use the 'add' event on the store and fill it with code something like this:
var myStore = Ext.create("Ext.data.Store", {
listeners: {
add: function(store, records){
var checkRecords = store.getRange();//get the records to check against
//clean out the records from the set that were just added
for(var i = 0; i < records.length; i++)
Ext.Array.remove(checkRecords, records[i]);
for(var i = 0; i < checkRecords.length; i++)
{
for( var j = 0; j < records.length; j++)
{
if(checkRecords[i].get("primary_key") == records[j].get("primary_key"))
throw "Duplicate primary key: " + records[j].get("primary_key");
}
}
}
}
});
That code will throw an exception but not stop the record for being added.