1. #1
    Ext JS Premium Member skullbooks's Avatar
    Join Date
    Nov 2010
    Location
    Dillenburg, Hessen, Germany
    Posts
    35
    Vote Rating
    1
    skullbooks is on a distinguished road

      0  

    Default [EXT 4.1 RC3] loading phantom records from the backend into a grid

    [EXT 4.1 RC3] loading phantom records from the backend into a grid


    i have a strange problem and can't find anything about...

    i have a grid (models+store+...) that is loaded from my backend via REST.
    the backend sends a list of objects (some with id - these records exist in the database, and some without id - these records are phantom records).

    with ExtJS 4.0.7 this worked perfect, the records with id became the right id and the records without id where added as phantom records to the grid.

    since the update to 4.1 RC2/RC3 the records without id get the id 0 and are not phantoms

    this is really a problem, cause the user should save (create) the phantom records to the database by click on them. but Ext thinks they already exist in the database and tries to update them (REST) and this fails in the database.

    So what changed with the model/id/phantom stuff?

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,111
    Vote Rating
    470
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    (some with id - these records exist in the database, and some without id - these records are phantom records).
    When you say the backend sends a list of items .. you are referring to the data returned by the server?

    I will need more details about this as the server has full control at this point of what is send back.

    Regards,
    Scott.

  3. #3
    Ext JS Premium Member skullbooks's Avatar
    Join Date
    Nov 2010
    Location
    Dillenburg, Hessen, Germany
    Posts
    35
    Vote Rating
    1
    skullbooks is on a distinguished road

      0  

    Default


    the backend is our own php server side. so the server sends json like
    Code:
    {
        result: [{
            id: 50,
            text: "entry from database"
        },{
            id: null,
            text: "fake entry should be phantom"
        },{
            text: "also tried fake entry without id"
        },{...},...]
    }
    they all came to the store as real models and none of them is a phantom.

    with Ext 4.0.7 the records with id: null where phantom records.

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,111
    Vote Rating
    470
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    in reviewing the code I see 4.1 did add the following:

    Code:
     setId: function(id) {
         this.set(this.idProperty, id);
         this.phantom  = !(id || id === 0);  // << added in 4.1
     },
    You can try a quick override test for your model see if that helps:

    Code:
    Ext.override(Ext.data.Model, {
       setId: function(id) {
          this.set(this.idProperty, id);
      }
    });
    Regards,
    Scott.

  5. #5
    Ext JS Premium Member skullbooks's Avatar
    Join Date
    Nov 2010
    Location
    Dillenburg, Hessen, Germany
    Posts
    35
    Vote Rating
    1
    skullbooks is on a distinguished road

      0  

    Default


    that was also the line i found but i'm very confused because to me it seems that this method is never called.
    i did a console.log in the override that never came. the override itself works (checked by also overriding the constructor and did a log there and called the overridden.
    Code:
    Ext.override(Ext.data.Model, {
    	constructor: function() {
    		console.log("CONSTRUCT MODEL");
    		this.callOverridden(arguments);
    	},
    	setId: function(id) {
    		console.log("MODEL SET ID", id);
    		this.set(this.idProperty, id);
    	}
    });
    the construct log came the other did never

  6. #6
    Ext JS Premium Member skullbooks's Avatar
    Join Date
    Nov 2010
    Location
    Dillenburg, Hessen, Germany
    Posts
    35
    Vote Rating
    1
    skullbooks is on a distinguished road

      0  

    Default


    my workaround now is to set the phantom flag on the beginning of the first column renderer if there is no id.

    that isn't really nice but it works, and as far as my debugging skills in the ext source go, it seems to be a problem there but i really don't get the construction of an model and when there is the data to be set...

    a fix or hint for my problem that is not that ugly as my one would be nice...

  7. #7
    Sencha User
    Join Date
    Aug 2008
    Location
    Brasov, Romania
    Posts
    34
    Vote Rating
    1
    nan21eu is on a distinguished road

      0  

    Default


    did you try to set the model property useNull:true ?

    Example:

    Ext.define("CurrencyDs" ,{
    extend: 'Ext.data.Model',
    fields: [
    {name:"name", type:"string"},
    {name:"code", type:"string"},
    {name:"active", type:"boolean"},
    {name:"notes", type:"string"},
    {name:"id", type:"int", useNull:true},
    ............
    ],
    .....

    });

  8. #8
    Ext JS Premium Member skullbooks's Avatar
    Join Date
    Nov 2010
    Location
    Dillenburg, Hessen, Germany
    Posts
    35
    Vote Rating
    1
    skullbooks is on a distinguished road

      0  

    Default


    yes i did, but didn't help.

    after that model.get('id') returned null as is should but model.phantom is/was false anyway

Thread Participants: 2