PHPackages                             roaresearch/yii2-rmdb - 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. [Framework](/categories/framework)
4. /
5. roaresearch/yii2-rmdb

ActiveLibrary[Framework](/categories/framework)

roaresearch/yii2-rmdb
=====================

Yii 2 Library to create RMDB models and migrations

3.0.0(3y ago)02.2k12BSD-3-ClausePHPPHP ~8.1

Since Oct 1Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ROAResearch/yii2-rmdb)[ Packagist](https://packagist.org/packages/roaresearch/yii2-rmdb)[ RSS](/packages/roaresearch-yii2-rmdb/feed)WikiDiscussions main Synced yesterday

READMEChangelog (5)Dependencies (8)Versions (6)Used By (2)

Yii2 RMDB Classes
=================

[](#yii2-rmdb-classes)

Library with migrations and models to easily create RMDB tables and models.

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

[](#installation)

You can use composer to install the library `roaresearch/yii2-rmdb` by running the command;

`composer require roaresearch/yii2-rmdb`

or edit the `composer.json` file

```
require: {
    "roareasearch/yii2-rmdb": "*",
}
```

Usage
-----

[](#usage)

### Create Migrations

[](#create-migrations)

There are 3 migration classes for each type of RMDB tables.

#### `roaresearch\yii2\rmdb\migrations\CreatePivot`

[](#roaresearchyii2rmdbmigrationscreatepivot)

Uses the properties `$createdByColumn`, `$createdAtColumn` and methods `createdByDefinition()`, `createdAtDefinition()` to store the user and datetime a record was created.

```
use roaresearch\yii2\rmdb\migrations\CreatePivot;

class m170101_000001_product_sale extends CreatePivot
{
    public $createdByColumn = 'creation_user';
    public $createdAtColumn = 'creation_date';

    public function getTableName()
    {
        return 'product_sale';
    }

    public function columns()
    {
        return [
            'product_id' => ...,
            'sale_id' => ...,
        ];
    }

    public function compositePrimaryKeys()
    {
        return ['product_id', 'sale_id'];
    }
}
```

#### `roaresearch\yii2\rmdb\migrations\CreateEntity`

[](#roaresearchyii2rmdbmigrationscreateentity)

Extends the previous class adding the properties `$updatedByColumn`, `$updatedAtColumn` and methods `updatedByDefinition()`, `updatedAtDefinition()`to store the user and datetime a record was updated.

```
use roaresearch\yii2\rmdb\migrations\CreateEntity;

class m170101_000001_product extends CreateEntity
{
    public $createdByColumn = 'creation_user';
    public $createdAtColumn = 'creation_date';
    public $updatedByColumn = 'edition_user';
    public $updatedAtColumn = 'edition_date';

    public function getTableName()
    {
        return 'product';
    }

    public function columns()
    {
        return [
            'id' => $this->prymariKey()->...,
            'name' => ...,
        ];
    }
}
```

#### `roaresearch\yii2\rmdb\migrations\CreatePersistentEntity`

[](#roaresearchyii2rmdbmigrationscreatepersistententity)

A persistent entity remains stored in the database after the user deletes it.

The library [yii2tech/ar-softdelete](https://github.com/yii2tech/ar-softdelete)provides support for this functionality.

`CreateEntity` extends the previous class adding the properties `$deletedByColumn`, `$deletedAtColumn` and methods `deletedByDefinition()`, `deletedAtDefinition()` to store the user and datetime a record was deleted.

```
use roaresearch\yii2\rmdb\migrations\CreatePersistentEntity;

class m170101_000001_sale extends CreatePersistentEntity
{
    public $createdByColumn = 'creation_user';
    public $createdAtColumn = 'creation_date';
    public $updatedByColumn = 'edition_user';
    public $updatedAtColumn = 'edition_date';
    public $deletedByColumn = 'deletion_user';
    public $deletedAtColumn = 'deletion_date';

    public function getTableName()
    {
        return 'product';
    }

    public function columns()
    {
        return [
            'id' => $this->prymariKey()->...,
            'store_id' => ...,
        ];
    }
}
```

### RMDB Module

[](#rmdb-module)

This library uses a custom module to help configure all the extended models in an homologued way.

configure it in your `common\config\main.php` in `yii-app-advanced` and `common\config.php` in `yii-app-basic`.

```
use roaresearch\yii2\rmdb\Module as RmdbModule;

return [
    // ...
    'modules' => [
        'rmdb' => [
            'class' => RmdbModule::class,
            'timestampClass' => ..., // optional
            'blameableClass' => ..., // optional
            'softDeleteClass' => ..., // optional
            'timestampValue' => time(), // optional by default uses `now()`
            'defaultUserId' => 5, // optional
        ],
    ],
];
```

### Models

[](#models)

Like the migrations there are 3 classes for models.

#### `roaresearch\yii2\rmdb\models\Pivot`

[](#roaresearchyii2rmdbmodelspivot)

Adds protected properties `$createdByAttribute` and `$createdAtAttribute` to configure the names of the attributes. The class will automatically load the needed behaviors and configure them to use the attributes as provided by this properties.

```
class ProductSale extends \roaresearch\yii2\rmdb\models\Pivot
{
    protected $createdByAttribute = 'creation_user';
    protected $createdAtAttribute = 'creation_date';

    // rest of model methods and logic
}
```

#### `roaresearch\yii2\rmdb\models\Entity`

[](#roaresearchyii2rmdbmodelsentity)

Extends the previous class and adds protected properties `$updatedByAttribute`and `$updatedAtAttribute` to configure the names of the attributes. The class will automatically load the needed behaviors and configure them to use the attributes as provided by this properties.

```
class Product extends \roaresearch\yii2\rmdb\models\Entity
{
    protected $createdByAttribute = 'creation_user';
    protected $createdAtAttribute = 'creation_date';
    protected $updatedByAttribute = 'edition_user';
    protected $updatedAtAttribute = 'edition_date';

    // rest of model methods and logic
}
```

#### `roaresearch\yii2\rmdb\models\PersistentEntity`

[](#roaresearchyii2rmdbmodelspersistententity)

Extends the previous class and adds protected properties `$deletedByAttribute`and `$deletedAtAttribute` to configure the names of the attributes. The class will automatically load the needed behaviors and configure them to use the attributes as provided by this properties.

```
class Product extends \roaresearch\yii2\rmdb\models\PersistentEntity
{
    protected $createdByAttribute = 'creation_user';
    protected $createdAtAttribute = 'creation_date';
    protected $updatedByAttribute = 'edition_user';
    protected $updatedAtAttribute = 'edition_date';
    protected $deletedAtAttribute = 'deletion_user';
    protected $deletedAtAttribute = 'deletion_date';

    // rest of model methods and logic
}
```

This model uses the `SoftDeleteActiveQuery` class which add 2 methods to filter based on the deletion status of a record.

- deleted()
- notDeleted()

This methods will use columns `$deletedByAttribute` and `$deletedByAttribute`to determine if a record was soft deleted or not. To prevent conflicts in joins the attributes are normalized with the query alias. For this reason **the `alias()` method must be called before the `deleleted()` or `notDeleted()`**.

```
Product::find()
  ->alias('p')
  ->notDeleted()
  ->innerJoin('brand b')
```

#### Testing Environment

[](#testing-environment)

This library use [Composer Utils](https://github.com/ROAResearch/composer-utils)to quickly deploy the needed database and testing Environment.

```
git clone https://github.com/ROAResearch/yii2-rmdb.git
cd yii2-rmdb/
composer deploy
```

This will ask db credentials, validate them and create the needed database and structure.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 84.9% 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 ~276 days

Total

5

Last Release

1309d ago

Major Versions

2.1.1 → 3.0.02022-10-12

PHP version history (2 changes)2.0.0PHP &gt;=7.1

3.0.0PHP ~8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/2341d88f3cdea0c2474cfbf59e5cf6dab5dd6a026d7846fabf219f2a93be1641?d=identicon)[neverabe](/maintainers/neverabe)

---

Top Contributors

[![Faryshta](https://avatars.githubusercontent.com/u/2029247?v=4)](https://github.com/Faryshta "Faryshta (45 commits)")[![neverabe](https://avatars.githubusercontent.com/u/1173807?v=4)](https://github.com/neverabe "neverabe (8 commits)")

---

Tags

frameworkmigrationyii2advancedmigratermdbrelational model database

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/roaresearch-yii2-rmdb/health.svg)

```
[![Health](https://phpackages.com/badges/roaresearch-yii2-rmdb/health.svg)](https://phpackages.com/packages/roaresearch-yii2-rmdb)
```

###  Alternatives

[funson86/yii2-adminlte

Yii 2 Advanced Application Template with Adminlte Theme

1492.2k](/packages/funson86-yii2-adminlte)[izyue/yii2-app-advanced

Yii 2 Advanced Project Template

1281.9k](/packages/izyue-yii2-app-advanced)[beaten-sect0r/yii2-core

Yii2 Core project template

771.1k](/packages/beaten-sect0r-yii2-core)

PHPackages © 2026

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