PHPackages                             queencitycodefactory/trash - 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. queencitycodefactory/trash

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

queencitycodefactory/trash
==========================

Adds soft delete support to CakePHP 3 ORM tables.

1.2.1(2y ago)05MITPHP

Since Sep 16Pushed 2y agoCompare

[ Source](https://github.com/QueenCityCodeFactory/Trash)[ Packagist](https://packagist.org/packages/queencitycodefactory/trash)[ Docs](https://github.com/queencitycodefactory/trash)[ RSS](/packages/queencitycodefactory-trash/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Trash
=====

[](#trash)

[![Build Status](https://camo.githubusercontent.com/5ea6c98c245cc6f193a2ff21a778e7eadd1ea30155b9a455f777445b81f4a4b4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f5573654d756666696e2f54726173682f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/UseMuffin/Trash)[![Coverage](https://camo.githubusercontent.com/3331e86897ddb876a8871b0ee8533caa62f18326851b1c36673057c6c3d949dc/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f5573654d756666696e2f54726173682f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/UseMuffin/Trash)[![Total Downloads](https://camo.githubusercontent.com/7fefc55a4e6c13c031dd439d96c3f6ba492d5167c58cd5c4989bedba104bf381/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d756666696e2f74726173682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/muffin/trash)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Adds "soft"-delete support to CakePHP 3 tables.

Install
-------

[](#install)

Using [Composer](http://getcomposer.org):

```
composer require queencitycodefactory/trash

```

You then need to load the plugin. You can use the shell command:

```
bin/cake plugin load QueenCityCodeFactory/Trash

```

or by manually adding statement shown below to `Application.php`:

```
$this->addPlugin('QueenCityCodeFactory/Trash');
```

Usage
-----

[](#usage)

In your table(s), add the behavior like you would for any other behavior:

```
// in the initialize() method
$this->addBehavior('QueenCityCodeFactory/Trash.Trash');
```

By default, the behavior will auto-detect the `DATETIME` column used to track trashed (soft-deleted) records but only if you are using `deleted` or `trashed` as names. Otherwise, you could customize that when adding the behavior:

```
// in the initialize() method
$this->addBehavior('QueenCityCodeFactory/Trash.Trash', [
    'field' => 'deleted_at'
]);
```

or, at the global level, in `bootstrap.php`:

```
Configure::write('QueenCityCodeFactory/Trash.field', 'deleted_at');
```

Finally, if you would like to keep the default cake behavior when running `find()` or `delete()` operations and explicitly call the behavior when you need 'trash'-ing functionality, just disable the event(s):

```
// in the initialize() method
$this->addBehavior('QueenCityCodeFactory/Trash.Trash', [
    'events' => ['Model.beforeFind'] // enables the beforeFind event only, false to disable both
]);
```

### Cascading deletion

[](#cascading-deletion)

If you'd like to have related records marked as trashed when deleting a parent item, you can just attach the behavior to the related table classes, and set the `'dependent' => true, 'cascadeCallbacks' => true` options in the table relationships.

This works on relationships where the item being deleted in the owning side of the relationship. Which means that the related table should contain the foreign key.

### Custom Finders

[](#custom-finders)

- **onlyTrashed** - helps getting only those trashed records.
- **withTrashed** - when filtering out the trashed records by default, this method comes in handy to have them included as part of certain calls.

### Extras

[](#extras)

- **emptyTrash()** - permanently deletes all trashed records.
- **restoreTrash($entity = null)** - restores one (or all) trashed records.
- **trash($entity)** - like `delete()` but for a soft-delete (handy when `Model.beforeDelete` is disabled by default).
- **trashAll(array $conditions)** - like `deleteAll()` but for soft-deletes.

Patches &amp; Features
----------------------

[](#patches--features)

- Fork
- Mod, fix
- Test - this is important, so it's not unintentionally broken
- Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
- Pull request - bonus point for topic branches

To ensure your PRs are considered for upstream, you MUST follow the CakePHP coding standards.

Bugs &amp; Feedback
-------------------

[](#bugs--feedback)

License
-------

[](#license)

Copyright (c) 2015, [Use Muffin](http://usemuffin.com) and licensed under [The MIT License](http://www.opensource.org/licenses/mit-license.php).

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.3% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

966d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bb4029cfc5efed64ab84fcfaca36cc23fc8c50d8e321086dfc67abf4747ef9b?d=identicon)[darensipes](/maintainers/darensipes)

---

Top Contributors

[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (21 commits)")[![jadb](https://avatars.githubusercontent.com/u/33527?v=4)](https://github.com/jadb "jadb (5 commits)")[![Spriz](https://avatars.githubusercontent.com/u/3512268?v=4)](https://github.com/Spriz "Spriz (4 commits)")[![adayth](https://avatars.githubusercontent.com/u/1223929?v=4)](https://github.com/adayth "adayth (2 commits)")[![dakota](https://avatars.githubusercontent.com/u/83255?v=4)](https://github.com/dakota "dakota (2 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (2 commits)")

---

Tags

ormcakephptrashmuffinqueencitycodefactory

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/queencitycodefactory-trash/health.svg)

```
[![Health](https://phpackages.com/badges/queencitycodefactory-trash/health.svg)](https://phpackages.com/packages/queencitycodefactory-trash)
```

###  Alternatives

[muffin/trash

Adds soft delete support to CakePHP ORM tables.

851.3M11](/packages/muffin-trash)[josegonzalez/cakephp-upload

CakePHP plugin to handle file uploading sans ridiculous automagic

5451.3M9](/packages/josegonzalez-cakephp-upload)[muffin/webservice

Simplistic webservices for CakePHP

88191.0k13](/packages/muffin-webservice)[muffin/slug

Slugging support for CakePHP ORM

38264.8k5](/packages/muffin-slug)[admad/cakephp-sequence

Sequence plugin for CakePHP to maintain ordered list of records

46489.9k6](/packages/admad-cakephp-sequence)[riesenia/cakephp-duplicatable

CakePHP ORM plugin for duplicating entities (including related entities)

51384.5k4](/packages/riesenia-cakephp-duplicatable)

PHPackages © 2026

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