1
votes

I have a view containing 2 grids. The grids are backed by 2 models. The relationship between the 2 models is one to many(keyless association).

Models:

Ext.define('TestApp.model.association.Project', {
    extend: Ext.data.Model,
    fields: [
        {
            type: 'int',
            name: 'id'
        }, {
            type: 'string',
            name: 'project'
        }, {
            type: 'number',
            name: 'allocation'
        }, {
            type: 'string',
            name: 'comments'
        }, {
            type:'string',
            name:'state'
        }
    ]
});


Ext.define('TestApp.model.association.User', {
    extend: Ext.data.Model,
    fields: [{
        type: 'int',
        name: 'id'
    }, {
        type: 'string',
        name: 'employee'
    }, {
        type: 'string',
        name: 'location'
    }, {
        type: 'string',
        name: 'department'
    }, {
        type: 'string',
        name: 'manager'
    }, {
        type: 'number',
        name: 'allocation'
    }],
    hasMany: [{
        model: 'TestApp.model.association.Project',
        // Note: use of 'role' is preferred over 'name'
        role: 'projects',
        // Define role for inverse association
        inverse: {
            role: 'user'
        }
    }]
});

After I edit one row from the child part, I set the parent record as dirty (dirty=true) and then I sync the store. After I do the necessary work on the server I send back the response. After I receive the response the dirty flag on the child part remains true.

When having no association, after receiving the response from the server, the dirty flag is clear automatically.

I've created a fiddle for more details.

How to clear the dirty flag from an association after an update?

Edit

I've updated the fiddle to better show my problem. Steps to reproduce:

  • Select John Doe record from the top panel
  • Select Apple from the bottom panel
  • Edit allocation and comments column (row edit plugin available). Press Ok
  • Press the Save button from the toolbar of the second grid

The request is sent to the server. The server respond with a json (the server response is hardcoded an will always be the same).

The client is unable to set the child record received in the response and clear the dirty flag.

Why is doing this? Is this a bug?

1
Are you dependent upon server for setting dirty flag, or can you code for it for setting dirty flag for parent->child.Tejas
@Tejas1991 i didn't quite understand your statement. I send a json to the server containing the changes. The server answer with a json containing the record after it was persisted into the db. It's a rest application. The dirty state is set on client after I do some changesflorin
Why dont you programatically set field's dirty flag instead of setting server's data to it ? Do one thing can you tell me about your code where you are setting server's dataTejas
@Tejas1991 On the server side, I have a spring boot application. After receiving the changes, I persist them into the db. As response I return the modified record.florin
Dirty flag is being set true when field's originalValue!=currentValue ,so in this case I think you must check after data is set into field then what is its originalValue.Tejas

1 Answers

0
votes

While setting up associations, all associated models must belong to the same schema. With reference to this, I have made some changes to your code. Please check if the Save button is working now. I have also commented out some parts of your code for initial test.

Find the code here