Threaded View

  1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    16
    Answers
    1
    Vote Rating
    0
    kornicameister is on a distinguished road

      0  

    Default Answered: Successful post, but infinite update loop after

    Answered: Successful post, but infinite update loop after


    Hi, I am having very strange issue with my code.
    I have two models Company and Warehouse associated in following way:
    Company hasOne Warehouse -> client (extjs) side
    Company is associated with Warehouse on primary key join column manner -> hibernate, server

    Problem occurs when I try to create new company along with warehouse and this is what I am sending to the server
    Code:
    {"data":[{"id":0,"name":"d","longName":"d","warehouse_id":0,"warehouse":{"id":0,"name":"d","description":"d","size":100,"createdDate":"2012-12-03T00:00:00","usage":"0.00"}}]}
    I am able to receive successful server's answer that both company and warehouse had been insterted into tables.
    This is the answer
    Code:
    • action: "CREATE"
    • data: [{longName:d, warehouse:{id:4, name:d, createdDate:0-338-2012, description:d, usage:0, size:100},…}]
      • 0: {longName:d, warehouse:{id:4, name:d, createdDate:0-338-2012, description:d, usage:0, size:100},…}
        • id: 4
        • longName: "d"
        • name: "d"
        • warehouse: {id:4, name:d, createdDate:0-338-2012, description:d, usage:0, size:100}
          • createdDate: "0-338-2012"
          • description: "d"
          • id: 4
          • name: "d"
          • size: 100
          • usage: 0
    • entity: "wms.model.Company"
    • handler: "wms.controller.CompanyController"
    • message: "CREATE took 108ms and affected 1 rows"
    • success: true
    • time: 108
    • total: 1
    As you can see company and warehouse ID are the same which is good. But right after POST, PUT is triggered with following payload
    Code:
    {"data":[{"id":4,"name":"d","longName":"d","warehouse_id":0}]}

    Here warehouse_id is magically gone and I don't have any idea why.

    In one word client goes in infinite loop with server by sending PUT request with exact same payload and receiving exact same answers with the difference on action in response's object.

    Here is the code for company and warehouse model on the client side
    Code:
    
    
    Code:
    Ext.define('WMS.model.entity.Company', {
        extend      : 'WMS.model.abstract.Simple',
        requires    : [
            'WMS.model.entity.Warehouse'
        ],
        fields      : [
            { name: 'longName', type: 'string' },
            { name: 'warehouse_id', type: 'int', mapping: 'warehouse.id'}
        ],
        associations: [
            {
                type           : 'hasOne',
                name           : 'warehouse',
                associationName: 'warehouse',
                instanceName   : 'warehouse',
                foreignKey     : 'warehouse_id',
                model          : 'WMS.model.entity.Warehouse',
                getterName     : 'setWarehouse',
                setterName     : 'getWarehouse'
            }
        ],
        proxy       : {
            type  : 'wms',
            url   : 'wms/agent/company',
            writer: {
                type          : 'json',
                root          : 'data',
                allowSingle   : false,
                writeAllFields: false,
                getRecordData : function (record, operation) {
                    var company,
                        action = operation['action'];
                    if (action === 'create') {
                        var company = record.getData(),
                            warehouse = record['warehouse'];
    
    
                        company['warehouse'] = warehouse.getData();
                        var warehouseID = company['warehouse_id'];
                        if (Ext.isDefined(warehouseID) && warehouseID === 0) {
                            delete company['warehouse_id'];
                        }
                    } else {
                        company = record.getData();
                    }
                    return company;
                }
            }
        }
    });
    Code:
    Ext.define('WMS.model.entity.Warehouse', {
        extend      : 'WMS.model.abstract.DescribedSimple',
        fields      : [
            { name: 'usage', type: 'float', defaultValue: 0.0, convert: convertUsage},
            { name: 'size', type: 'int', defaultValue: 0},
            { name: 'createdDate', type: 'date', serialize: serializeDate}
        ],
        proxy       : {
            type: 'wms',
            url : 'wms/agent/warehouse'
        }
    });

  2. Thanks for the feedback but I am forced to deny any more help.
    The problem was in the following fragment of the code
    Code:
    getterName    : 'setWarehouse'
    setterName    : 'getWarehouse'
    
    I think that it could be more hilarious...
    thanks anyway ;-)

Thread Participants: 1

Tags for this Thread