Questions tagged [soft-delete]

Soft delete is to delete data from database in a way in which it can be recovered in the future rather than permanently deleting the data,

Soft delete, in database terminology, means to delete data from a database by generally marking it with flag like isDeleted rather than permanently deleting data. Soft delete helps in preserving data such that it can be recovered in the future rather than actually deleting it. Soft deleting also prevents accidental data losses.

367 questions
151
votes
26 answers

Physical vs. logical (hard vs. soft) delete of database record?

What is the advantage of doing a logical/soft delete of a record (i.e. setting a flag stating that the record is deleted) as opposed to actually or physically deleting the record? Is this common practice? Is this secure?
user21826
  • 3,524
  • 5
  • 28
  • 28
136
votes
15 answers

Are soft deletes a good idea?

Are soft deletes a good idea or a bad idea? Instead of actually deleting a record in your database, you would just flag it as IsDeleted = true, and upon recovery of the record you could just flag it as False. Is this a good idea? Is it a better idea…
001
  • 62,807
  • 94
  • 230
  • 350
72
votes
5 answers

How to check if row is soft-deleted in Eloquent?

In Laravel 5.1 is there a nice way to check if an eloquent model object has been soft-deleted? I'm not talking about selecting data but once I have the object e.g. Thing::withTrashed()->find($id) So far the only way I can see is if…
DisgruntledGoat
  • 70,219
  • 68
  • 205
  • 290
49
votes
3 answers

Laravel Soft Delete restore() Error

The following soft delete code works fine for me: $post = Post::find($post_id); $post->delete(); The deleted_at field is updated. But this gives me an error: $post = Post::find($post_id); $post->restore(); Here's the error: exception…
sterfry68
  • 1,063
  • 2
  • 14
  • 30
40
votes
5 answers

Cascading Soft Delete

SQL has always had a great feature: cascading deletes. You plan it in advance and when it's time to delete something, BAM! No need to worry about all those dependent records. However, nowadays it's almost taboo to actually DELETE anything. You flag…
Arthur Chaparyan
  • 2,015
  • 6
  • 29
  • 35
37
votes
7 answers

Why soft deleted entities appear in query results?

I am trying to implement soft deleting concept. Here is my object: class Post extends Eloquent { /** * The database table used by the model. * * @var string */ protected $table = 'posts'; protected $softDelete =…
Sergey Sob
  • 815
  • 1
  • 12
  • 27
31
votes
7 answers

Soft delete best practices (PHP/MySQL)

Problem In a web application dealing with products and orders, I want to maintain information and relationships between former employees (users) and the orders they handled. I want to maintain information and relationships between obsolete products…
user479911
28
votes
3 answers

Filter all navigation properties before they are loaded (lazy or eager) into memory

For future visitors: for EF6 you are probably better off using filters, for example via this project: https://github.com/jbogard/EntityFramework.Filters In the application we're building we apply the "soft delete" pattern where every class has a…
Moeri
  • 9,104
  • 5
  • 43
  • 56
26
votes
5 answers

How to soft delete related records when soft deleting a parent record in Laravel?

I have this invoices table that which has the following structure id | name | amount | deleted_at 2 iMac 1500 | NULL and a payments table with the following structure id | invoice_id | amount | deleted_at 2 2 1000 |…
user3407278
  • 1,233
  • 5
  • 16
  • 32
17
votes
4 answers

Listener "SoftDeleteableListener" was not added to the EventManager

I followed the this example to test softdeletable extension on my project running Symfony 2.1.0-DEV. I configured my config.yml like below: orm: auto_generate_proxy_classes: %kernel.debug% auto_mapping: true filters: …
Ricky Li
  • 191
  • 1
  • 1
  • 6
14
votes
4 answers

How to disable soft delete (Soft-deleteable) filter for doctrine in symfony

Installing and using SoftDeleteable behavior extension for Doctrine 2 is quite easy. The problem usually is trying to disable it for some code part and enabling again. You may want to do this to: load entity that is soft-deleted remove entity from…
Aurelijus Rozenas
  • 2,176
  • 2
  • 28
  • 40
13
votes
2 answers

How to implement an append-only versioned model in SQLAlchemy

I would like to re-implement some of my existing SQLAlchemy models in an append-only datastore; append-only meaning that object are only updated with INSERT statements, not using UPDATE or DELETE statements. The UPDATE and DELETE statements would be…
lyschoening
  • 18,170
  • 11
  • 44
  • 54
11
votes
1 answer

Soft Delete Cascading with Laravel 5.2

I'm trying to implement soft deleting in Laravel. Here are my relationships Tournament ( hasMany ) CategoryTournament (hasOne) CategorySettings Tournament ( hasMany ) CategoryTournament (belongsToMany) CategoryTournamentUser So, I used this answer…
Juliatzin
  • 18,455
  • 40
  • 166
  • 325
11
votes
1 answer

SoftDelete on Many to many table in Doctrine 1.2

I can add the SoftDelete behaviour on a ManyToMany reference table, this will add a deleted_at column. Unfortunately setting the column to a not NULL value, will not filter out the relations. This is what I had hoped. Does anybody know a workaround…
Michiel Thalen
  • 300
  • 2
  • 12
11
votes
4 answers

Softdeletable behaviour and really deleting the entity

I'm using DoctrineExtensions with StofDoctrineExtensionsBundle to get the soft-deleteable behaviour. It works really well in the frontend of my application. In the backend i need the option to "hard" delete entities. I have disabled the filter in…
smoove
  • 3,920
  • 3
  • 25
  • 31
1
2 3
24 25