Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6222009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:14:14+00:00 2026-05-24T08:14:14+00:00

My problem consists of not being able to retrieve data through associations. After running

  • 0

My problem consists of not being able to retrieve data through associations.
After running setup() from console i would expect firstTurbine.getPlant() to return the associated plant, yet it returns undefined.
I’ve spent alot of time looking for a solution I’m probably not looking the right place.

Relevant code is attached below:

Ext.regApplication({
            name: "app",
            launch: function() {
                //app.views.viewport = new app.views.Viewport(); 
            }
});

app.models.Plant = Ext.regModel("Plant", {
    fields: [
        {name: "id", type: "int"},
        {name: "name", type: "string"},
        {name: "notes", type: "auto"}
    ],
    proxy: {type: 'localstorage', id:'plantStorage'}
});

app.models.Turbine = Ext.regModel("Turbine", {
    fields: [
             {name: "id", type: "int"},
             {name: "plant_id", type: "int"},

             {name: "name", type: "string"},
             {name: "notes", type: "auto"}
             ],
    proxy: {type: 'localstorage', id:'turbineStorage'},
    belongsTo: 'Plant'
});

app.stores.plants = new Ext.data.Store({
    model: "Plant",
    autoLoad: true,
    data : [
            {id: 1, name: 'Plant1', notes: ["Note1", "Note2"]},
            {id: 2, name: 'Plant2', notes: ["Note1", "Note2"]},
            {id: 3, name: 'Plant3', notes: ["Note1", "Note2"]}
        ]
});

app.stores.turbines = new Ext.data.Store({
    model: "Turbine",
    autoLoad: true,
    data: [
           {id: 11, "plant_id": 1, name: "T41", notes: ["Turbine note 1", "Turbine note 2"]},
           {id: 12, "plant_id": 1, name: "T13", notes: ["Turbine note 1", "Turbine note 2"]}
          ]
});

function setup(){
    firstPlant = app.stores.plants.getAt(0);
    if(!firstPlant){
        firstPlant = Ext.ModelMgr.create({name:"TestPlant1", id: 1}, "Plant");
      app.stores.plants.add(firstPlant);
      app.stores.plants.sync();
    }

    firstTurbine = app.stores.turbines.getAt(0);
    if(!firstTurbine){
      firstTurbine = Ext.ModelMgr.create({name:"T31", id: 30, plant_id: 1}, "Turbine");
      app.stores.turbines.add(firstTurbine);
      app.stores.turbines.sync();
    }

    return {firstTurbine: firstTurbine, firstPlant: firstPlant};
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:14:15+00:00Added an answer on May 24, 2026 at 8:14 am

    The getter function created by the belongsTo association takes a callback function as argument. The callback function will have the related object as its first argument.

    turbine.getPlant(function(Plant){
                    console.log(Plant);
                });
    

    I will attach a full working example since this have cost me alot of headache and might have aswell for others.

    first the json data:

    {
    "plants": [{
            "id": 1,
            "name": "Plant1",
            "notes": ["Note1", "Note2"]
        }],
    "turbines": [
        {
            "id": 11,
            "plant_id": 1,
            "name": "T41",
            "notes": ["Turbine note 1", "Turbine note 2"]
        }]
    }
    

    And the javascript:

    Ext.regApplication({
                    name: "app",
                    launch: function() {}
                });
    
    app.models.Plant = Ext.regModel("Plant", {
        fields: ["id", "name", "notes"],
        proxy: {
            type: 'ajax',
            url: 'data.json',
            reader: {
                type: 'json',
                root: 'plants'
            }
        }
    });
    
    app.models.Turbine = Ext.regModel("Turbine", {
        fields: ["id", "plant_id", "name", "notes"],
        proxy: {
            type: 'ajax',
            url: 'data.json',
            reader: {
                type: 'json',
                root: 'turbines'
            }
        },
        belongsTo: 'Plant'
    });
    
    app.stores.plants = new Ext.data.Store({
        model: "Plant"
    });
    
    app.stores.turbines = new Ext.data.Store({
        model: "Turbine",
        autoLoad: {
            callback: function(records) {
                var turbine = records[0];
    
                turbine.getPlant(function(Plant){
                    console.log(Plant);
                });
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is with .Net Http/Uri libraries not being able to decode or unescape
Summing up, my problem consists on compiling g95 objects inside a C++ application. Actually,
Problem: I have an address field from an Access database which has been converted
Problem: Given a list of strings, find the substring which, if subtracted from the
Problem Language: C# 2.0 or later I would like to register context handlers to
Problem I have timestamped data, which I need to search based on the timestamp
Problem solved: Thanks guys, see my answer below. I have a website running in
I'm new to MyBatis and my project requires me to read the data from
Would a hashtable/hashmap use a lot of memory if it only consists of object
Our system setup consists of two Weblogic 10.3 servers: one hosts the presentation layer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.