PHPackages                             tecnocen/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. tecnocen/yii2-rmdb

ActiveLibrary[Framework](/categories/framework)

tecnocen/yii2-rmdb
==================

Yii 2 Library to create RMDB models and migrations

1.0.1(6y ago)19.7k13BSD-3-ClausePHPPHP &gt;=5.5

Since Oct 23Pushed 6y ago3 watchersCompare

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

READMEChangelog (5)Dependencies (4)Versions (6)Used By (3)

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

[](#yii2-rmdb-classes)

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

Instalation
-----------

[](#instalation)

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

`composer require tecnocen/yii2-rmdb`

or edit the `composer.json` file

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

Usage
-----

[](#usage)

### Create Migrations

[](#create-migrations)

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

#### `tecnocen\rmdb\migrations\CreatePivot`

[](#tecnocenrmdbmigrationscreatepivot)

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

```
class m170101_000001_product_sale extends \tecnocen\rmdb\migrations\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'];
    }
}
```

#### `tecnocen\rmdb\migrations\CreateEntity`

[](#tecnocenrmdbmigrationscreateentity)

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

```
class m170101_000001_product extends \tecnocen\rmdb\migrations\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' => ...,
        ];
    }
}
```

#### `tecnocen\rmdb\migrations\CreatePersistentEntity`

[](#tecnocenrmdbmigrationscreatepersistententity)

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.

```
class m170101_000001_sale extends \tecnocen\rmdb\migrations\CreateEntity
{
    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 unified way.

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

```
use tecnocen\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.

#### `tecnocen\rmdb\models\Pivot`

[](#tecnocenrmdbmodelspivot)

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 \tecnocen\rmdb\models\Pivot
{
    protected $createdByAttribute = 'creation_user';
    protected $createdAtAttribute = 'creation_date';

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

#### `tecnocen\rmdb\models\Entity`

[](#tecnocenrmdbmodelsentity)

Extends the previos 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 \tecnocen\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
}
```

#### `tecnocen\rmdb\models\PersistentEntity`

[](#tecnocenrmdbmodelspersistententity)

Extends the previos 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 \tecnocen\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
}
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 94.4% 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 ~147 days

Total

5

Last Release

2533d ago

Major Versions

0.1.2 → 1.0.02019-05-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d5f64412ef020f8c137ff5c7f5e4a0866271f2f9ba9584e5a24aa48467f958d?d=identicon)[Faryshta](/maintainers/Faryshta)

![](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 (17 commits)")[![neverabe](https://avatars.githubusercontent.com/u/1173807?v=4)](https://github.com/neverabe "neverabe (1 commits)")

---

Tags

frameworkmigrationyii2advancedmigratermdbrelational model database

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/tecnocen-yii2-rmdb/health.svg)](https://phpackages.com/packages/tecnocen-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)
