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

  • SEARCH
  • Home
  • 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 9208047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:31:51+00:00 2026-06-18T00:31:51+00:00

Hope you are doing good. I am new in extjs4 and working on sample

  • 0

Hope you are doing good.

I am new in extjs4 and working on sample example of association.

I have 2 different class User and Diploma
In relation, I have defined.

User hasMany Diplomas, and Diplomas belongsTo User

My models are as belows

User.js

Ext.define('MyApp.model.User', {
    extend : 'Ext.data.Model',
    idProperty : 'userId',
    fields : [{
        name : 'userId',
        type : 'integer'
    }, {
        name : 'userName',
        type : 'string',

    }],

    hasMany : {
        model : 'MyApp.model.Diploma',
        name : 'diplomas',
    },

});

Diploma.js

Ext.define('MyApp.model.Diploma', {
    extend : 'Ext.data.Model',
    idProperty : 'diplomaId',
    fields : [{
        name : 'diplomaId',
        type : 'integer'
    }, {
        name : 'diplomaName',
        type : 'string',
    }, {
        name : 'userId',
        type : 'integer'
    }],

    associations : [{
        model : 'MyApp.model.User',
        name : 'user',
        type : 'belongsTo'
    }]

});

=====================
My Stores are as below.========================

Diploma.js

Ext.define('MyApp.store.Diploma', {
    extend : 'Ext.data.Store',
    model : 'MyApp.model.Diploma',
    autoLoad : true,

    listeners : {
        'load' : {
            fn : function(store, records, success, operation) {
                console.log('Diplomas are loaded');
            }
        }
    }

});

User.js

  Ext.define('MyApp.store.User', {
        extend : 'Ext.data.Store',
        model : 'MyApp.model.User',
        requires:['Ext.data.proxy.LocalStorage'],
        autoLoad : true,

        listeners : {
            'load' : {
                fn : function(store, records, success, operation) {
                    console.log('User is loaded');
                }
            }
        },

        data : [{
            userId : 1,
            userName : 'Rishabh Shah',
            diplomas:{
                userId : 1,
                diplomaId:1,
                diplomaName:'IT'
            }
        }, {
            userId : 2,
            userName : 'Rakesh Shah',
            diplomas:{
                userId : 2,
                diplomaId:2,
                diplomaName:'CE'
            }
        }, {
            userId : 3,
            userName : 'Rashmin Shah'
        }],

        proxy:{
            type:'memory',
            reader:{
                root:'data'
            }
        }
    });

I can get diploma from user like that and can get result

Ext.getStore("User").getAt(0).diplomasStore.getAt(0)

but, when I try to do like

Ext.getStrore("Diploma") or Ext.getStrore("Diploma").getAt(0)

I don’t get anything. items contains nothing…
How can I get user from diploma.

and One more thing….if I don’t write proxy in my Diploma model..
it gives me an error like this..

Ext.data.proxy.Server.buildUrl(): You are using a ServerProxy but have not supplied it with a url.

Please guide me.

Thanks.


Thanks for your reply..@john..I can get diplomas from User..
I wanted to get user from diplomas…I tried it myself..and found solution…

I will have following json.

[
    {
        "depId": 1,
        "depName": "CE",
        "employees": [
            {
                "empId": 1,
                "firstName": "Rishabh",
                "lastName": "Shah"
            }, {
                "empId": 2,
                "firstName": "Smit",
                "lastName": "Patel"
            }
        ]
    }, {
        "depId": 2,
        "depName": "IT",
        "employees": [
            {
                "empId": 1,
                "firstName": "Parag",
                "lastName": "Raval"
            }, {
                "empId": 2,
                "firstName": "Rakesh",
                "lastName": "Prajapati"
            }
        ]
    }, {
        "depId": 3,
        "depName": "EE",
        "employees": [
            {
                "empId": 1,
                "firstName": "Parag EE",
                "lastName": "Raval EE"
            }, {
                "empId": 2,
                "firstName": "Rakesh EE",
                "lastName": "Prajapati EE"
            }
        ]
    }, {
        "depId": 4,
        "depName": "EC",
        "employees": [
            {
                "empId": 1,
                "firstName": "Parag EC",
                "lastName": "Raval EC"
            }, {
                "empId": 2,
                "firstName": "Rakesh EC",
                "lastName": "Prajapati EC"
            }
        ]
    }, {
        "depId": 5,
        "depName": "Chemial E",
        "employees": [
            {
                "empId": 1,
                "firstName": "Parag",
                "lastName": "Raval"
            }, {
                "empId": 2,
                "firstName": "Rakesh",
                "lastName": "Prajapati"
            }
        ]
    }, {
        "depId": 6,
        "depName": "ME",
        "employees": [
            {
                "empId": 1,
                "firstName": "Parag",
                "lastName": "Raval"
            }, {
                "empId": 2,
                "firstName": "Rakesh",
                "lastName": "Prajapati"
            }
        ]
    }, {
        "depId": 7,
        "depName": "Civil Engineer",
        "employees": [
            {
                "empId": 1,
                "firstName": "Parag",
                "lastName": "Raval"
            }, {
                "empId": 2,
                "firstName": "Rakesh",
                "lastName": "Prajapati"
            }
        ]
    }
]

and I will use model.getAssociatedData().user as per my requirement

where model is my record of child class and user is my parent class..

and I was using proxy in my Diploma Model which was not requierd….so, was getting

Ext.data.proxy.Server.buildUrl(): You are using a ServerProxy but have not supplied it with a url.

above mentioned error.

Thanks All ! 🙂

  • 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-06-18T00:31:52+00:00Added an answer on June 18, 2026 at 12:31 am

    What exactly isn’t working? Have you been able to use the magic methods e.g., User.diplomas()? As @VDP stated, the store created for the Association is a normal Ext.data.Store scoped to the set of data for the parent model (in this case, User). That is to say, if you have a User model with the id of 1, calling the method User.diplomas() will return a Ext.data.Store filtered to contain only Diploma‘s with a user_id of 1.

    This is very important to understand! If you do not specify the foreignKey property in a hasMany association, it will default to the lowercased name of the owner model plus “_id”, You should amend your User model’s hasMany association as so:

    Ext.define('MyApp.model.User', {
    /** Model Definition */
    hasMany : {
        model : 'MyApp.model.Diploma',
        name : 'diplomas',
        foreignKey : userId /** This is what you're missing */
    }
    });
    

    Perhaps you will find this blog post useful? http://extjs-tutorials.blogspot.com/2012/05/extjs-hasmany-relationships-rules.html

    Some important tips from the blog post (in case the link dies at some point)

    • Always put your Proxies in your Models, not your Stores, unless you
      have a very good reason not to *
    • Always require your child models if using them in hasMany
      relationships. **
    • Always use foreignKey if you want to load the children at will
    • Always use associationKey if you return the children in the same
      response as the parent
    • You can use both foreignKey and associationKey if you like
    • Always name your hasMany relationships
    • Always use fully qualified model names in your hasMany relationship
    • Consider giving the reader root a meaningful name (other than “data”)
    • The child model does not need a belongsTo relationship for the
      hasMany to work

    *The store will inherit its model’s proxy, and you can always override it

    **To make it easy, and avoid potential circular references, you can require them in app.js

    Credit: Neil McGuigan (http://www.blogger.com/profile/14122981831780837323)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope you are doing good. I have 2 different class University and Students Relation
hope you are doing good. I am setting a label and adjusting its frame
I'm neither good nor experienced about asking questions so i hope I'm not doing
I hope I am doing this correctly.. Using this code I am grabbing records
I hope this is something straightforward that I'm doing wrong. I saw something online
Hope the AWK gurus can provide a solution to my problem . I have
hope someone can answer this. Here is some sample code. namespace std { #ifdef
Hope someone could help me with this: I would like to have a column
Hope someone will give me a hand with this problem I have. So here
mmmh guys, i really hope my english is good enaught to explain what i

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.