PDA

View Full Version : Store record - updating phantom attribute



Jangla
10 Mar 2013, 4:02 PM
When does the phantom attribute get removed on a record? At the moment I have a store that is having records added to it and subsequently calling save to commit to the database using the CRUD api settings.

Only thing is, the previously newly created record in the store still has it's phantom status. it also still has it's "temporary" id that was assigned to it when it was created.

So, do I have to manually update the record after saving the store? I could reload the store but it would seem like a waste of resource to have to make another request to the server right after I've just made one to create the record.

mitchellsimoens
12 Mar 2013, 8:35 AM
Phantom means that it was created in the client and was not synced to the backend. Are you using an id? How are you saving?

Jangla
12 Mar 2013, 8:47 AM
The record won't have an id when it's created - the id is PK in the db so Ext assigns it an id of 'ext-record-1'

Saving with the store.save() method. record still has phantom attribute true after saving. To be honest, I've seen many posts about possible issues with this in 3.4 and have now stripped out CRUD, opting to manually trigger ajax updates when needed. I may put CRUD back in for our ongoing ext 4 update but I'm unsure if it's worth it if it's so problematic. It's obviously partly due to us wanting this "no save button" type interface where records in a list can be created by users whenever they like and only saved once certain attributes on the record have been completed.

mitchellsimoens
12 Mar 2013, 8:56 AM
Ok, Ext will create an id but if you return the id from say a store.sync() it will update the record's id and set phantom to false.

Jangla
12 Mar 2013, 9:03 AM
yea, that's an option but it's kinda pointless to make a server call to create a record and then make another call to update the store so it's id's are all correct. doubling the server calls just to get this working isn't worth it :D

mitchellsimoens
12 Mar 2013, 9:12 AM
I never said do 2 calls.

Jangla
12 Mar 2013, 9:15 AM
sorry, I assumed the sync call would call the server to ratify the records. also, store.sync() is ext 4, no?

mitchellsimoens
12 Mar 2013, 9:28 AM
sorry, I assumed the sync call would call the server to ratify the records. also, store.sync() is ext 4, no?

I'm sorry... store.save()

Jangla
12 Mar 2013, 9:38 AM
that's what I was calling.

mitchellsimoens
12 Mar 2013, 9:41 AM
Ok, so what were you responding with then?

aw1zard2
12 Mar 2013, 9:52 AM
Depending on how your sending the data to the back on things like this if you have a temp id send it to the backend then you can update the record in the store and commit on the 1 record. If you want no notifications/events fired do record.commit(true);

Below is example code pasted from the 3.4.0 API Docs for Ext.data.Record.


// record has a field named 'firstname'
var Employee = Ext.data.Record.create([
{name: 'firstname'},
...
]);

// update the 2nd record in the store:
var rec = myStore.getAt(1);

// set the value (shows dirty flag):
rec.set('firstname', 'Betty');

// commit the change silently (removes dirty flag):
rec.commit(true);

// update the record in the store, bypass setting dirty flag,
// and do not store the change in the modified records
rec.data['firstname'] = 'Wilma'; // updates record, but not the view
rec.commit(); // updates the view