Results 1 to 2 of 2

Thread: Forms loadRecord loading Associated data?

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    25
    Answers
    2

    Default Forms loadRecord loading Associated data?

    Is it possible to populate form fields with nested data (associations)?

    I have a grid which is filled with instances of a "LineItem" model. The lineItem model looks like this:

    Code:
    Ext.define('LineItem', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id', mapping: 'item_id', type: 'int'},
            'item_display_number',
            'item_name'
            // Removed for brevity
        ],
        validations: [
            {type: 'presence', field: 'item_name'}
        ],
        associations: [{
            type         : 'hasMany',
            model        : 'GL'
        }]
    });
    When a LineItem model is selected from the grid we call loadRecord() on the form and push in the record which the user selected which populates my form with item_display_number, item_name, etc.

    I have six other fields in the form which need to be populated through the selected models associated GL model. Here is a link to some JSON that the server would return to the Proxy of my LineItem model. The six fields on my form are Comboboxes and their value should be set to the "job_type" of each GL model within the GL Array property from the server.

    I did some googling for this and came across a blog post by Aaron Smith of Modus Create last summer. Is this considered the proper way to solve this still or has Sencha worked something into the code since mid 2012?

  2. #2
    Sencha User
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5

    Default I totally recommend that approach

    I don't honestly know if Sencha has addressed this or not yet, but it should be easy enough to figure out by looking at the latest source. I'd expect they'd solve this in a way similar. I should say that the approach I used in that and related articles all made their way into production and didn't cause any maintenance headaches.

    -Aaron
    Aaron N. Smith
    @aaron_n_smith
    Software Architect
    Modus Create, Inc.

Posting Permissions

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