PHP code example of roaresearch / yii2-rmdb

1. Go to this page and download the library: Download roaresearch/yii2-rmdb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

roaresearch / yii2-rmdb example snippets


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'];
    }
}

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' => ...,
        ];
    }
}

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' => ...,
        ];
    }
}

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
        ],
    ],
];

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

    // rest of model methods and logic
}

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
}

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
}

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