Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    219
    Vote Rating
    9
    dedoz will become famous soon enough

      0  

    Default [4.1-RC1] Model load method wont use configured idProperty

    [4.1-RC1] Model load method wont use configured idProperty


    i think this bug has been posted before, but is still there so here goes again.
    Ext version tested:
    ExtJs 4.1 beta 1, beta 2 , beta 3, RC1

    Browser versions tested against:
    Firefox 10.0.2
    Chrome 17.0.963.66

    Description:
    Model load static method will always send a request with a field with name "id" and wont use the configured model idProperty.

    Steps to reproduce the problem:
    Define a simple model with a configured idProperty
    Run Model.load()
    check the http request data

    The result that was expected:
    send the configured idProperty name and value to the server

    The result that was expected:
    always sends a value under the key "id"

    Test Case:
    Code:
        // just setting a provider to give you full code to test
        // doenst need to configure anything else
        // select method doesnt need to exists in the server side, the problem happens when sending
        Ext.direct.Manager.addProvider({
            "url":"php\/router.php",
            "type":"remoting",
            "actions":{
                "testQuery":[
                    {"name":"personSelect","len":1}
                ]
            }
        });
        
        Ext.define('Person', {
            extend: 'Ext.data.Model',
            fields: [
                {name:'someId'    ,       type:'int'}
            ],
            idProperty: 'someId',
            proxy: { type: 'direct', 
                api:{ 
                    read    : testQuery.personSelect
                } 
            }
        });
        Person.load(45,{callback: function(record) {}}); 
         
        // results in 
        //   sends this {"action":"testQuery","method":"personSelect","data":[{"id":45}],"type":"rpc","tid":1}
        //   check the "id":45
        // should be 
        //   "someId":45
        
    also getter (associated record) have the same problem, because they use the the same load method
    can check this just adding a belongsTo association and run getSomething(), and check the request
    it doesnt need to be a belongsTo to the same model, just doing this to show less code
    Code:
        ... code same provider ...
        Ext.define('Person', {
            extend: 'Ext.data.Model',
            fields: [
                {name:'someId'    ,       type:'int'},
                {name:'parentId'    ,       type:'int'}
            ],
            belongsTo : [
                {model: 'Person', foreignKey:'parentId', getterName : 'getParent'}
            ],
            idProperty: 'someId',
            proxy: { type: 'direct', 
                api:{ 
                    read    : testQuery.personSelect
                } 
            }
        });
        
        var p = Ext.create('Person',{
            someId : 1,
            parentId : 3
        })
        
        p.getParent();
         
        //   sends this {"action":"testQuery","method":"personSelect","data":[{"id":3}],"type":"rpc","tid":1}
        //   check the "id":3
        // should be 
        //   "someId":3 
        
    but at the end is the same problem, because getter uses Model.Load static method.



    Source of problem
    one part seems to come from src/data/model
    Code:
        Ext.define('Ext.data.Model',{
            ........
            inheritableStatics: {
                ........
                load: function(id, config) {
                    ........
                    config = Ext.applyIf(config, {
                        action: 'read',
                        id    : id
                    });    
                    ........
                }
            }
        });
    seems like the id from argments its always passed in a id key, not using the idProperty
    tested to change that to the current configured idProperty
    doing
    Code:
            var cfg = { 
                action : 'read'
            }
            cfg[this.prototype.idProperty] = id;
            config = Ext.applyIf(config, cfg);
    this actually set "someId" : 45 and sends it to the reader but then goin to the reader seems like he always expect an id config property,
    because doing this the request now looks like

    {"action":"testQuery","method":"personSelect","data":[{}],"type":"rpc","tid":1}

    i guess reader didnt find the key "id" in the config.
    so dunno but theres the problem i think.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,649
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    This looks to be the same issue as : http://www.sencha.com/forum/showthread.php?152511

    Can you confirm?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    219
    Vote Rating
    9
    dedoz will become famous soon enough

      0  

    Default


    yeah but i dont agree with your comment
    Quote Originally Posted by mitchellsimoens View Post
    I have moved this to the bugs forum and entered as a bug as the idProperty should change the parameter that is sent back. This isn't a bug per-say but an improvement.
    this is actually a bug, the field name to send to the server in the request needs to be the configured idProperty not "id" because model doesnt have a field "id", not in ext model definition not in the server side.

  4. #4
    Touch Premium Member
    Join Date
    Jun 2008
    Posts
    43
    Vote Rating
    0
    bhutten is on a distinguished road

      0  

    Default


    This bug is still present in 4.2.1 - I just wasted a couple hours tracking it down. Specifically, the problem occurs with the static Model.load() method. Doing a regular record.save() works correctly.

    I have
    Code:
    idProperty: '_id'
    set on both the model, and the model's proxy.



    - bill

Thread Participants: 2