PHPackages                             zunderbolt/cakephp-softdelete-trait - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. zunderbolt/cakephp-softdelete-trait

ActiveCakephp-plugin[Database &amp; ORM](/categories/database)

zunderbolt/cakephp-softdelete-trait
===================================

Soft delete trait for CakePHP models

51.8kPHP

Since Dec 3Pushed 11y ago1 watchersCompare

[ Source](https://github.com/zunderbolt/cakephp-softdelete-trait)[ Packagist](https://packagist.org/packages/zunderbolt/cakephp-softdelete-trait)[ RSS](/packages/zunderbolt-cakephp-softdelete-trait/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

CakePHP Soft Delete Trait
=========================

[](#cakephp-soft-delete-trait)

Soft delete trait for using with CakePHP 2.x models.

Sometimes it is useful to flag records as deleted instead of physically removing them from the database. Achieving that with this plugin requires no custom delete method calls or custom find conditions to exclude deleted records - your models delete() and find()/read() will just work. It is also possible to fetch deleted records when needed or perform "hard" delete.

Requirements
------------

[](#requirements)

- CakePHP 2.x
- PHP 5.4+

Installation
------------

[](#installation)

### With Composer

[](#with-composer)

```
"require": {
    "zunderbolt/cakephp-softdelete-trait": "dev-master"
}

```

### Manual

[](#manual)

- Download files to `APP/Plugin/SoftDeleteTrait`

Configuration
-------------

[](#configuration)

- Load plugin with `CakePlugin::load('SoftDeleteTrait');` in `bootstrap.php` or where needed.
- Show the app where to look for source file `App::uses('SoftDeleteTrait', 'SoftDeleteTrait.Lib');` or load it with your autoloader.
- Use the trait in your model and implement method `_deletedFieldName`, which should return the name of database field for deletion tracking.
- Don't forget to add the field in your database table. It can be boolean flag (TINYINT/INT field, 1 for deleted record, 0 otherwise), date or datetime (NULL for normal record, date/datetime of removal for deleted record).

Example:

```
    App::uses('SoftDeleteTrait', 'SoftDeleteTrait.Lib');

    class Item extends AppModel {
        use SoftDeleteTrait;

        protected function _deletedFieldName() {
            return 'isDeleted';
        }
```

Usage notes
-----------

[](#usage-notes)

Soft delete and exclusion of deleted records from find/read results works automagically. To include deleted records in find results use $this-&gt;includeDeletedRecords() in your model. To exclude them again use the excludeDeletedRecords() method.

To save some additional data for deleted records you can implement protected method \_additionalFieldsForDeletedRecord() in your model. For example, you can set record's status and removal reason:

```
    protected function _additionalFieldsForDeletedRecord() {
        return [
            'removalReason' => 'Useless stuff',
            'status'        => self::STATUS_DELETED
        ];
    }
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/74f6a06c63dcb8e0f8414682c156316a822ee8340cc36ac3f8344c7de75a7c94?d=identicon)[ZunderBolt](/maintainers/ZunderBolt)

---

Top Contributors

[![zunderbolt](https://avatars.githubusercontent.com/u/2702403?v=4)](https://github.com/zunderbolt "zunderbolt (2 commits)")

---

Tags

cakephpcakephp2modelphpsoftdeletetrait

### Embed Badge

![Health badge](/badges/zunderbolt-cakephp-softdelete-trait/health.svg)

```
[![Health](https://phpackages.com/badges/zunderbolt-cakephp-softdelete-trait/health.svg)](https://phpackages.com/packages/zunderbolt-cakephp-softdelete-trait)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
