Results 1 to 2 of 2

Thread: No store for nested model on parent

  1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    15
    Vote Rating
    0
      0  

    Default No store for nested model on parent

    Hi I have two models with an association and a store.

    Code:
    Ext.regModel("App.models.QuestionSet", {
        fields: [
            {name: "id", type: "string"},
            {name: "title", type: "string"},
            {name: "text", type: "string"},
            {name: "date", type: "string"},
        ],
        hasMany  : {associatedModel: 'Question', name: 'questions'}
    });
    
    Ext.regModel("App.models.Question", {
        fields: [
            {name: "id", type: "string"},
        {name: "questionSetId", type: "string"},
            {name: "title", type: "string"},
            {name: "text", type: "string"},
            {name: "date", type: "string"},
        ]
    });
    
    Ext.regStore('QuestionSetStore', {
        model: 'App.models.QuestionSet',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'data/QuestionSet.json',
            reader: {
               type: 'json',
               root: 'data'
            }
        }
    });
    I have the following JSON

    Code:
    {
        "success": "true",
        "data": [
            {
                "id": "1",
                "title": "Question Set A",
                "questions": [
                    {
                        "text": "Question 1",
                        "id": "1"
                    },
                    {
                        "text": "Question 2",
                        "id": "2"
                    },
                    {
                        "text": "Question 3",
                        "id": "3"
                    }
                ]
            }
        ]
    }
    If run the code below I was expecting to see a function 'questions' under the QuestionSet instance that would return the nested store for the questions however I do not. Under the raw property of the QuestionSet I can see a questions array with the correct data. Can anyone explain what I should be seeing as I am finding this a bit hit and miss but not entirely sure what I am missing. TIA

    Code:
    var store = Ext.StoreMgr.get('QuestionSetStore');
    store.each(function(record) { 
        console.log(record);
    });

  2. #2
    Sencha User edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    11
      0  

    Default

    I think you'd have to change your first association to reference the full Model name:

    Code:
    hasMany  : {associatedModel: 'App.models.Question', name: 'questions'}
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •