Results 1 to 3 of 3

Thread: Loading nested data into two different stores

  1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    2
    Vote Rating
    0
      0  

    Default Loading nested data into two different stores

    I have two models that are related. One is called 'Changes' and belongsTo a 'Configuration'. This is how I've defined the association on a 'Change':

    Code:
    associations: [{
                type:'belongsTo', 
                model:'Changes.model.Configuration',
                primaryKey: 'id',
                foreignKey: 'configuration_id',
                associationKey: 'configurations'
            }],
    On the changes store I have a proxy defined like this:
    Code:
    proxy: {
                type: 'ajax',
                url: 'services/changes.php',
                reader: {
                    type: 'json',
                    rootProperty: 'changes'
                }
           },
    When the store is loaded it is passed a JSON object that looks like this:
    Code:
    {
        "success": true,
        "changes": [
            {
                "id": 1,
                "changeId": "CMS19178263",
                "briefDescription": "Loaded from Proxy!!!",
                "configuration_id": 3,
                "configurations": [
                    {
                        "id": "3",
                        "longName": "002669-2669-abc_-_windows_7_desktop.Computer.Windows",
                        "ciName": "002669-2669-abc_-_windows_7_desktop"
                    }
                ]
            }
        ]
    }
    When the record gets loaded I can call 'record.getConfiguration()' but all of the fields in 'data' show null (except id shows: ext-record-9). Inside the raw array there is one object that shows all of the fields with the data loaded from the JSON. Can anyone see why the data isn't being read into a new Configuration object and saved to the Configuration store?

    Let me know if I need to post anymore information...

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Try making the configurations property value an object instead of an array in your JSON.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    2
    Vote Rating
    0
      0  

    Default

    Doing that made it so the configuration showed up as an associated object of the change. But it doesn't load it into the configuration store. Now I'm thinking it's going to be better to load the two stores separately (with flat instead of nested JSON). But will the change objects get automatically associated with their respective configuration objects if the associations definitions are setup correctly on each model? Or is that not a feature built into the framework?

    Quote Originally Posted by mitchellsimoens View Post
    Try making the configurations property value an object instead of an array in your JSON.

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
  •