Results 1 to 7 of 7

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

  1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    6

    Default Answered: [ExtJS 4.1.1RC1] model with idgen -> new phantom = false. why?

    The issue: Creating new Records with model that uses idgen is not a phantom
    because of the next statement in constructor of model

    Code:
    if (me.getId()) {
                me.phantom = false;        
    } else if (me.phantom) {
                newId = me.idgen.generate();
                if (newId !== null) {
                    me.setId(newId);
                }
    }
    Model.setId code:
    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
    Attached Files Attached Files

  2. 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.

  3. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,256
    Answers
    759

    Default

    By giving the model an id, that makes it not a phantom record anymore.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    6

    Default

    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?

  5. #4
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,256
    Answers
    759

    Default

    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.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  6. #5
    Sencha User
    Join Date
    Jun 2011
    Posts
    6

    Default

    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. #6
    Sencha Premium User
    Join Date
    Dec 2010
    Posts
    217
    Answers
    4

    Default Thanks for the advice BUT

    Hi,
    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.

  8. #7
    Sencha Premium Member
    Join Date
    Oct 2014
    Posts
    5

    Default client side id generation

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •