Results 1 to 3 of 3

Thread: Problem with hasMany-association and model-proxy

  1. #1
    Ext JS Premium Member
    Join Date
    Mar 2010
    Location
    Cologne
    Posts
    37
    Answers
    2

    Question Answered: Problem with hasMany-association and model-proxy

    Hi everyone,

    I've run into a weird problem that you may checkout on jsfiddle:
    https://jsfiddle.net/phill54/bewd46ka/21/

    I'm failing at associating two models when the nested model uses a custom proxy.
    I was hoping someone would be able to help me out why that is and if there's a workaround for that.

    In the jsfiddle-example everything works fine. The problem occurs when trying to uncomment the proxy of the order.line model.
    Code:
            Ext.define('Order',{
                extend: 'Ext.data.Model'
                ,fields: [ 'id', 'customerId', 'totalGross']
                ,associations: [{
                    type: 'hasMany',
                    model: 'Order.Line',
                    associationKey: 'lines',
                    name: 'lines',
                    primaryKey: 'id',
                    autoLoad: false,
                    foreignKey: 'orderId'
                }]
                ,proxy: {
                    type: 'custom-rest',
                    url: '/api/order', // redirected to /echo/json/ when loading
                    extraParams: {
                        'with': 'lines'
                    }
                }
            });
    
    
            Ext.define('Order.Line', {
                extend: 'Ext.data.Model',
                fields: ['id', 'title', 'totalGross']
                /* if you uncomment the following 4 lines, the demo wont
                 * work no more. wtf?!? why is that? can anyone help?
                 */
    //            ,proxy: {
    //                type: 'custom-rest',
    //                url: '/api/order/line'
    //            }
            });

  2. solved.

    https://jsfiddle.net/phill54/bewd46ka/23/

    Code:
            Ext.define('Order',{
                extend: 'Ext.data.Model'
                ,fields: [ 'id', 'customerId', 'totalGross']
                ,associations: [{
                    type: 'hasMany',
                    model: 'Order.Line',
                    associationKey: 'lines',
                    name: 'lines',
                    primaryKey: 'id',
                    autoLoad: false,
                    foreignKey: 'orderId',
                    reader: {} // override default reader of model !!!
                }]
                ,proxy: {
                    type: 'custom-rest',
                    url: '/api/order', // redirected to /echo/json/ when loading
                    extraParams: {
                        'with': 'lines'
                    }
                }
            });
    I had to override the default reader of my custom-proxy with an empty reader when associating the nested model.

  3. #2
    Ext JS Premium Member
    Join Date
    Mar 2010
    Location
    Cologne
    Posts
    37
    Answers
    2

    Default

    I figured it's because of the proxy reader configuration.
    https://jsfiddle.net/phill54/bewd46ka/22/

    when i configure my proxy reader to point to specific success/message/total-Properties, the nested model causes the whole store.load() to fail.

    has anyone an idea how to fix this?
    do i need seperate proxy-readers for nested and not-nested models?

    Code:
            /* this is the proxy i want to use for all of my models */        Ext.define('CustomProxy', {
                extend: 'Ext.data.proxy.Rest',
                alias: 'proxy.custom-rest',
                sortParam: 'order',
                startParam: (function () {})(), //set to undefined
                pageParam: 'page',
                limitParam: 'pageSize',
                actionMethods: {
                    create: 'POST', read: 'POST',
                    update: 'POST', destroy: 'POST'
                },
                reader: {
                    type: 'json'
                    ,root: 'data'
                 /* if i uncomment the following 3 lines, the demo wont
                 * work no more. wtf?!? why is that? can anyone help?
                 */
    //                ,successProperty: 'meta.success'
    //                ,messageProperty: 'meta.message'
    //                ,totalProperty: 'cursor.totalCount'
                }
            });
    Last edited by phill54; 7 Jul 2015 at 2:12 AM. Reason: typo

  4. #3
    Ext JS Premium Member
    Join Date
    Mar 2010
    Location
    Cologne
    Posts
    37
    Answers
    2

    Default

    solved.

    https://jsfiddle.net/phill54/bewd46ka/23/

    Code:
            Ext.define('Order',{
                extend: 'Ext.data.Model'
                ,fields: [ 'id', 'customerId', 'totalGross']
                ,associations: [{
                    type: 'hasMany',
                    model: 'Order.Line',
                    associationKey: 'lines',
                    name: 'lines',
                    primaryKey: 'id',
                    autoLoad: false,
                    foreignKey: 'orderId',
                    reader: {} // override default reader of model !!!
                }]
                ,proxy: {
                    type: 'custom-rest',
                    url: '/api/order', // redirected to /echo/json/ when loading
                    extraParams: {
                        'with': 'lines'
                    }
                }
            });
    I had to override the default reader of my custom-proxy with an empty reader when associating the nested model.
    Last edited by phill54; 7 Jul 2015 at 2:38 AM. Reason: closing thread

Similar Threads

  1. Replies: 2
    Last Post: 19 Feb 2015, 4:49 AM
  2. Replies: 5
    Last Post: 14 Nov 2014, 4:18 AM
  3. Replies: 2
    Last Post: 30 Jan 2013, 11:09 AM
  4. Problem with localstorage store and model with hasMany association
    By kostysh in forum Sencha Touch 2.x: Discussion
    Replies: 14
    Last Post: 26 Jul 2012, 5:53 AM
  5. Replies: 2
    Last Post: 10 Apr 2012, 10:27 AM

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
  •