[CLOSED] Store GetChangedData and Phantom record confusion

  1. #1

    [CLOSED] Store GetChangedData and Phantom record confusion

    When I add a new record to store, I want to generate the ID property on the clientside. But when I set the ID property on the record, it marks the record as not phantom...so it's not new. What's the logic behind this? It seems silly and counterintuitive that I can't generate IDs on the clientside.
    Last edited by Daniil; Mar 21, 2013 at 7:12 AM. Reason: [CLOSED]
  2. #2
    Any record which has id automatically becomes to non phantom.

    Text from phantom property documentation
    True when the record does not yet exist in a server-side database (see setDirty). Any record which has a real database pk set as its id property is NOT a phantom -- it's real.
    Such logic is implemented in ExtJS Model class. You can try to set phantom property to true manually after adding to a store (please note that by default id value of phatom records is not passed to the server during sync action)

    Can you explain a reason why do you need to set id on the client side?
    Vladimir Shcheglov
    Sr. Developer
  3. #3
    Because there are alot of javascript code that references records by id. So when the record doesn't have a generated ID, all my functions break for new records. I need the ID to be a format of a GUID string. I even tried manually setting phantom = true but in your custom getChangedData function, it strips out the id property from the return data to the server.
  4. #4
    Because there are alot of javascript code that references records by id.
    Why don't you want to save records first before using that code? Also you can use internalId property of the record and getByInternalId method of store to find a record

    I even tried manually setting phantom = true but in your custom getChangedData function, it strips out the id property from the return data to the server.
    Yes, as I mentioned before, id is not passed for phantom records to the server (because, by default, store expects real id from the server for phantom records). You can change that behaviour using SkipIdForPhantomRecords propety of Writer
    Vladimir Shcheglov
    Sr. Developer
  5. #5
    skipID property worked for me. Thanks!

    But for your other question, here's a scenario of why IDs should be generated on the clientside:

    1 grid with Order and 1 grid with OrderLineItems. When adding a new order, I need to set the OrderGUID on that record so when creating new order line items for that new order, I can set the OrderLineItem.OrderGUID. I obviously do not want to save the new order when the add a new Order record because they may to want to add a bunch of orders and a bunch of order line items before saving.

    IMO, this is ExtJS guys being lazy and trying to pigeonhole how we suppose to manage records. They are assuming that new records will get saved to a database and it's the database's job to generate new IDs. Maybe they are assuming only autoincrement IDs should be used? Being a clientside framework, they shouldn't force us into certain serverside patterns.
  6. #6
    It is definitely good to ask on the Sencha forum.

Similar Threads

  1. Replies: 0
    Last Post: Nov 20, 2012, 1:08 PM
  2. Replies: 1
    Last Post: Nov 05, 2012, 8:38 AM
  3. Replies: 1
    Last Post: Dec 22, 2011, 6:17 AM
  4. Replies: 16
    Last Post: May 26, 2011, 10:23 PM
  5. Replies: 5
    Last Post: May 15, 2009, 7:40 AM

Posting Permissions