PHPackages                             sibds/yii2-trash-behavior - 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. sibds/yii2-trash-behavior

ActiveYii2-behaviors[Database &amp; ORM](/categories/database)

sibds/yii2-trash-behavior
=========================

AR models behavior that allows to mark models as deleted and then restore them.

v0.4.2(9y ago)22.6k↓83.3%1MITPHPPHP &gt;=5.4.0

Since Jun 15Pushed 8y ago5 watchersCompare

[ Source](https://github.com/sibds/yii2-trash-behavior)[ Packagist](https://packagist.org/packages/sibds/yii2-trash-behavior)[ Docs](https://github.com/sibds/yii2-trash-behavior)[ RSS](/packages/sibds-yii2-trash-behavior/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (1)

yii2-trash-behavior
===================

[](#yii2-trash-behavior)

AR models behavior that allows to mark models as deleted and then restore them.

[![Build Status](https://camo.githubusercontent.com/c37a52730ad372aafc087a8decf6ee805b4127648a6290ff768d4db16f748542/68747470733a2f2f7472617669732d63692e6f72672f73696264732f796969322d74726173682d6265686176696f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sibds/yii2-trash-behavior)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/00ab3c223c499c71f810f7973463c3cf9f302cd5dc215fc24142e2bf75a62a5e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73696264732f796969322d74726173682d6265686176696f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sibds/yii2-trash-behavior/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/ad994e1dd688d2a65adf08dc6150562e3c309a6bad7a46cc57d304a0ca9fdbc0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73696264732f796969322d74726173682d6265686176696f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sibds/yii2-trash-behavior/?branch=master)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require sibds/yii2-trash-behavior
```

or add

```
"sibds/yii2-trash-behavior": "*"

```

to the `require` section of your `composer.json` file.

How to use?
-----------

[](#how-to-use)

Paste in the model code:

```
  public function behaviors()
  {
      return [
          \sibds\behaviors\TrashBehavior::className(),
      ];
  }
```

To mark a record for deletion, call function `delete`:

```
  $model->delete();
```

The second call `delete`, delete the record.

To restore record:

```
  $model->restore();
```

For the correct selection of records in the model, it is necessary to redefine the function of `find`:

```
  public static function find()
  {
      return (new \sibds\behaviors\TrashQuery(get_called_class()))->findRemoved();
  }
```

Example of use:

```
  $posts = Post::find()->all();
```

Selecting only marked for deletion of records:

```
  $count = Post::find()->onlyRemoved()->count();
```

Selecting all records:

```
  $allPosts = Post::find()->withRemoved()->all();
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

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

Every ~234 days

Total

4

Last Release

3288d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f6efd9689c925cb52664846422950fa2ffe7cd9c44b9644eda8479499c104076?d=identicon)[mazurva](/maintainers/mazurva)

---

Top Contributors

[![mazurva](https://avatars.githubusercontent.com/u/1152567?v=4)](https://github.com/mazurva "mazurva (22 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

yii2Behavioractive-recordtrash

### Embed Badge

![Health badge](/badges/sibds-yii2-trash-behavior/health.svg)

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

###  Alternatives

[voskobovich/yii2-linker-behavior

This behavior makes it easy to maintain many-to-many and one-to-many relations in your ActiveRecord models.

80319.0k9](/packages/voskobovich-yii2-linker-behavior)[sjaakp/yii2-sortable-behavior

Sort ActiveRecords and related records in Yii2.

36144.7k](/packages/sjaakp-yii2-sortable-behavior)[nanson/yii2-postgis

Yii2-extension to work with postgis data

1851.6k](/packages/nanson-yii2-postgis)[edgardmessias/yii2-firebird

Firebird connector for Yii2 framework

2415.5k](/packages/edgardmessias-yii2-firebird)[arogachev/yii2-tree

Database tree structures management for Yii 2 framework

222.1k](/packages/arogachev-yii2-tree)

PHPackages © 2026

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