extjsassociationsextjs4.2extjs-stores

What are associations between models for?


What are associations between models for ?

I understand, that they are useful to parse a nested json object from a server, a good example for this is in the docs. But this seems really limited to me.

Are there other uses where associations can be used and can simplify programming ?

I think about an example with two grids, where on show the details of the selected row in the other, like a grid of customers, and a grid showing the invoices for the currently selected user.


Solution

  • to answer the question with the grid:

    you need to set up a HasMany-association between the customer and invoices model. each defined with its own proxy. you will create two stores and bind them to the grids but only load the customers store.

    in the grid select listener you will do something like this:

    select: function( rowmodel, record, index, eOpts ) {
        var invoices = record.invoices().load(); // will issue a request on the invoices proxy
        invoicesStore.loadData(invoices);
    }
    

    Edit: example: Rules for HasMany Associations in ExtJS