1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    53
    Vote Rating
    0
    Answers
    3
    dishwashwebdesign is on a distinguished road

      0  

    Default Answered: hasmany relation two models one store trouble bubble

    Answered: hasmany relation two models one store trouble bubble


    Model Item
    Code:
    Ext.define('stockwiz.model.Item', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                { name: '_id',  type: 'string' },
                { name: 'name',  type: 'string' },
            ],
            hasMany: {model: 'Linkeditems', name: 'linkeditems'},
        }
    });
    Model Linkeditems
    Code:
    Ext.define('stockwiz.model.Linkeditems', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                { name: '_id',  type: 'string' },
                { name: '_item_id',  type: 'string' },
                { name: 'quantity',  type: 'float' },
                { name: 'notes',  type: 'string' },
            ],
            belongsTo: 'Item'
        }
    });
    JSON into Item Store
    Code:
    {
        "_id": "4fc608e66a41a65814000001",
        "name": "product link test",
        "linkeditems": [
            {
                "_item_id": "4fc5c91804e17e0100000001",
                "quantity": 10,
                "notes": ""
            },
            {
                "_item_id": "4fc5afeed501360100000002",
                "quantity": 1,
                "notes": ""
            }
        ]
    }
    Funny error when doing:
    Code:
    var myStore = Ext.StoreMgr.get('Item');
    var storeItem = myStore.first();
    console.log('linkeditems count: '+storeItem.linkeditems.getCount());
    TypeError: 'undefined' is not an object (evaluating 'storeItem.linkeditems.getCount')

    Whats wrong with that has-many setup?
    Kinda tried to take over logic from http://docs.sencha.com/touch/2-0/#!/....reader.Reader

    Thanks for any hints...

  2. Try setting the associationKey config in the hasMany config to "linkeditems"

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,656
    Vote Rating
    435
    Answers
    3108
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    Try setting the associationKey config in the hasMany config to "linkeditems"
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    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 almost in print!

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

  4. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    53
    Vote Rating
    0
    Answers
    3
    dishwashwebdesign is on a distinguished road

      0  

    Default


    thanks for the response, but this didn't help either.
    will just go back to the old-fashioned-kinda way of having a separate store and do the linking with filters instead
    cheers...

Tags for this Thread