Keep in sync: many deletes, some failed

I have a store where a user can delete multiple records with a single operation destroy

.

Now some of these entries are locked in the database (because someone is working on them) and therefore cannot be deleted. How can the server tell the front that deleting records with Id, b, c was successful, but records with Id x, y, z could not be deleted and should be returned to storage and displayed in the grid?

The ExtJS store needs to know afterwards sync()

which records were actually deleted on the server side and which weren't.

+3


source to share


1 answer


I think there is no easy solution to this problem. I chose the following workaround:

Entries now have an "IsDeleted" flag, which is set to by default false

:

fields:[{
    ...
},{
    name: 'IsDeleted'
    type: 'bool',
    defaultValue: false

      

The repository has a filter that hides entries where the flag is set to true

:



filters:[{
    property:'IsDeleted',
    value:false
}]

      

When the user chooses to delete, I do not enter the remove

records from the repository, instead I set a flag IsDeleted

in true

for these records. The filter makes the user think that the entry has been deleted.

When the store syncs, an operation is performed update

, not an operation destroy

. Thus, the API update endpoint must then delete all entries where IsDeleted

passed as true

. If it cannot delete an entry from the database, the corresponding json returned to the client gets IsDeleted

set to false

so that the frontend will know that deleting that entry failed.

0


source







All Articles