View Full Version : Method last() on stores

16 Dec 2011, 8:01 AM
I have a list that has a store in it that i sort by the property 'name'. after adding a record to the store i want to get it's 'id'. I'm used to using Mysql/PHP and just use mysql_insert_id() to get the 'id' of the just inserted record. So what i used with sencha was the last() method, but this gives the last item in the store depending on how it is sorted (which is logical, just didn't occur to me when i wanted to do what i needed). Right now i resort the store on the 'id' property, use last() and resort again so the list is still displayed the way it should be.
Shouldn't there be a method for a store that will give you the id of the last inserted record? This should be very useful in a lot of situations (unless the stores used are always sorted by id). Or am i missing something? Is there an easier way for me to do what i am doing?

16 Dec 2011, 9:24 AM
You should keep the record around until the sync returns with the updated data.

16 Dec 2011, 1:24 PM
how would that change what is returned by last()?

the result i am getting is after the store has synced (or at least after i have called sync() on the store). but after the sync the id returned by last() is still not the one that was last added, it returns the last record according to the way the store is sorted. unless you mean to keep the record around so i can get the id from that record instance, but that record is new and doesn't have an id untill it is added to the store, right?