View Full Version : [ExtJS 4.1.1RC1] model with idgen -> new phantom = false. why?

18 May 2012, 4:43 AM
The issue: Creating new Records with model that uses idgen is not a phantom
because of the next statement in constructor of model

if (me.getId()) {
me.phantom = false;
} else if (me.phantom) {
newId = me.idgen.generate();
if (newId !== null) {
Model.setId code:

setId: function(id) {
this.set(this.idProperty, id);
this.phantom = !(id || id === 0);

here in setId code whether or not id is generated by idgen the record marked as not phantom
here the example code

20 May 2012, 9:28 PM
By giving the model an id, that makes it not a phantom record anymore.

20 May 2012, 9:48 PM
so how then implement idgenerator and what is "the idgen" for?
i see that there is clientIdPorperty, but how can i assign autmaticly the value for the clientId?
any scenario, example, i didn't see any in the documantation.
and how the get new records from the store?

20 May 2012, 10:56 PM
A phantom record doesn't have an id. Lets take a common scenario:

1) You load a store with 5 records, these come from the server and all have an id assigned.
2) You add a new record to the store. It doesn't have an id, because it has yet to be created on the server (hence, phantom).
3) You run a sync on the store, the server assigns a new id to the record and sends it back to the client.
4) The record is no longer a phantom.

In your case, the idgen is just taking the place of the server.

20 May 2012, 11:52 PM
it is doubtful for my task :)
hense i don't have a way to push mass or records, that is related each other, from the client.
personnaly i use idgen to provide foreign key for "associations" and use it to connect objects in mongoDb (no referencial integrity at all).

I wonder, if there any way to do what i do(commit tree of connected objects), in relation database -- because client must at first save the master record and then connected one because of the integrity checking - foreign key.

the clientIdProperty didn't suits for my solution at all.

may be invent a state machine for the record using which developer and store will determine that record is newly created (thinking out loud).

7 Dec 2012, 7:14 AM
Although I agree guidance regarding DB's assigning ID's and I think the 'phantom' record functionality for new records is great the issue I have is that in my situation I NEED TO CREATE THE ID's on the CLIENT.

There's no reason why you need to enforce this restriction on not syncing new records with id's created on the client.
The fact that I can't add a record to a store with an ID and have it sync via the store's proxy is a defect.

30 Oct 2014, 4:32 AM
I have same problem. I need to create record on client with id and save it on the server. I think it is common situation, when model id should be created on client side.
Thread marked as "answered" , but I do not see any answer there.
I could set "phantom" property to true, as it is advised on many forums. But I not sure it will be ok.
There should be more normal way to do this.