1. #1
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
    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
    Gainesville, FL
    Posts
    36,620
    Answers
    3452
    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


    Try setting the associationKey config in the hasMany config to "linkeditems"
    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.

  4. #3
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
    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...

  5. #4
    Sencha User
    Join Date
    Sep 2010
    Posts
    27
    Vote Rating
    2
    dusoft is on a distinguished road

      0  

    Default I have the same problem, but your solution doesn't work for me...

    I have the same problem, but your solution doesn't work for me...


    I am going grazy!..
    Please, can you help me?


    See my post..


    http://www.sencha.com/forum/showthre...g-nested-json-
    Model-and-hasMany-association.

Thread Participants: 2

Tags for this Thread