logical deletion
logical deletion
comptabilitat
Posts: 10Questions: 3Answers: 0
in Editor
Hi,
I want to implement a logical deletion of a record using events on Datatables Editor for PHP.
When clicking delete I want to save '1' in a table field called 'deleted' instead of the physical deletion of the record.
That's my piece of code
public function llistesValors($post) {
Editor::inst( $this->editorDb, 'llistesValors' )
->fields(
Field::inst( 'id' ),
Field::inst( 'value' ),
Field::inst( 'deleted' )
)
->where('dt_deletion',null)
->on('preRemove', function($editor,$id,$values) {
$editor
->field('deleted')
->setValue(1);
return true;
})
->process( $post )
->json();
}
When I click delete button record disappears, but it remains in the database and 'deleted' field hasn't been updated.
Any idea?
Thanks
Carles
This discussion has been closed.
Replies
I found an interesting post about logical delete (or soft delete)
https://datatables.net/forums/discussion/35902
It works fine.
If you're using version 1.6.1 or above there is no need to modify Editor.php
Hi,
I've got an example showing how to do soft delete available here.
Allan