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 9005141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:04:09+00:00 2026-06-16T01:04:09+00:00

I am using ExtJS 4.1.0 Say I have a couple simple model’s connected via

  • 0

I am using ExtJS 4.1.0

Say I have a couple simple model’s connected via a hasMany association. The models represent an order and order contents…

Ext.define('App.model.Order', 
{
    extend: 'Ext.data.Model',
    fields: ['id', 'order_date', 'order_total', 'contents' ],
    associations: [{
            type           : 'hasMany',
            model          : 'App.model.OrderContents',
            name           : 'getContents', /** magic method */
            primaryKey     : 'id',
            foreignKey     : 'order_id',
            autoLoad       : false
    }],

    /** Proxy Definition here.. */

});

Ext.define('App.model.OrderContents', 
{
    extend: 'Ext.data.Model',
    fields: ['id', 'order_id', 'item_id' ],

    /** Proxy Definition here.. */

});

Now, what if I want the contents property of my App.model.Order to be automatically set when an Order model is instantiated? For a temporary solution, I have added the following method to the Order model:

Ext.define('App.model.Order', 
{

/** Model definition ... */

    loadContents: function()
    {
       this.getContents().load({
            callback: function()
            {
                this.set('contents', arguments[0]);
            },
            scope: this
        });

    }
});

In order to have an Order object with contents readily available, I must do the following:

var myOrder = new App.model.Order({id:1, order_date:'12-15-2012', order_total:100});
myOrder.getData(true); // contents will be null
myOrder.loadContents();
myOrder.getData(); // contents will be an array of OrderContents

I have tried overloading the constructor for App.model.Order but no matter what, I cannot get access to the data loaded by the association even if I perform a callback on the async request for the association data.

Ultimately I would like to be able to retrieve an Order from my App.store.Orders and have the retrieved record already have its contents property set, but I just can’t figure it out! If I retrieve a record from the store as follows:

myStore = Ext.getStore('OrderStore');
myOrder = myStore.findRecord('id',1);
myOrder.getData(); // contents will be null
myOrder.loadContents();
myOrder.getData(); // contents will be an array of OrderContents

I’m really just trying to cut down on having to .loadContents() for every instance of App.model.Order throughout my application; this seems like it should be very easy to accomplish. What am I missing?!

Thanks for your time!

  • 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-16T01:04:10+00:00Added an answer on June 16, 2026 at 1:04 am

    I managed a workaround by overloading the store‘s constructor:

    Ext.define('App.store.Orders', {
        extend: 'Ext.data.Store',
        storeId: 'OrdersStore',
        model: 'App.model.Order',
    
        constructor: function()
        {
            this.superclass.constructor.call(this);
            this.on('load', function(store, records, success, eOpts){
                Ext.each(records, function(order){
                   order.loadContents();
                });
            }, this);
        }
    });
    

    Hopefully this will help someone 🙂

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

Sidebar

Related Questions

I'm using extjs and just trying to solve a simple problem: I have a
Using ExtJs 4.1 Hi, I have a field in my model, where 1 =
I am using ExtJS 4. I have created a tree panel as var treeStore
I'm using extjs mvc style to create a web application. I don't have any
I'm using ExtJS 2.2.1 In my web app, I used to have a TreePanel
I'm using ExtJS 3.2 and have content inside of a tab panel, and the
I'm using ExtJS 3. I have a formPanel with many cloned fields and I
I created a grid using extjs library. First created a model: Ext.define('Option', { extend:
I am using extjs grid, and I have a jQuery timer, which will call
So, I've read a lot about using ExtJS's fileuploadfield to submit a form via

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.