PDA

View Full Version : Forms loadRecord loading Associated data?



caleywoods
9 Dec 2013, 1:03 PM
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:


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 (https://gist.github.com/caleywoods/c74bc6ba57c8af689379) 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 (http://moduscreate.com/expert-ext-js-associations-in-forms/) 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?

aaronnsmith
10 Dec 2013, 7:06 AM
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