Soft deletes with Symfony 2 [part 1]

So, you want to have soft deletes on Symfony? You have two choices:
- Do it by hand
- Install a Bundle

Install a Bundle

The bundle is You have to add it to your composer.json file and run "php composer.phar update"

Now you have to add the configuration to your config.yml file. Basically you are telling Symfony to add a Kernel event listener, the listener will listen to all the Doctrine delete actions and do the magic.

Now we have to create the DoctrineExtensionListener.php and save it to the AppBundle/EventListener folder. This is the file that starts the soft deletes process and is listening to Doctrine delete actions.

Now you have to edit the entities that gonna implement the soft deletes. You have to do it manually because not all the entities gonna need this feature.

Remember to update your schema "php app/console doctrine:schema:update" with the new deleted_at field. And that’s it, you could delete your entites, Symfony will return a null entity in case you delete it, but it’s gonna be on your database.

Show your support

Clapping shows how much you appreciated Fausto Carrera’s story.