qumuinc/ulidtypes

UlidType plugin for CakePHP

Maintainers

Details

github.com/Muuq/ulidtype

Source

Installs: 566

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 1

Type:cakephp-plugin

v0.0.5 2021-10-05 01:43 UTC

This package is not auto-updated.

Last update: 2024-04-16 17:44:32 UTC


README

Setup

Install

$ composer require qumuinc/ulidtypes

Bootstrap

  • add plugin load command in config/bootstrap.php
...
Plugin::load('qumuinc/UlidTypes', ['bootstrap' => true]);
...

Model

  • add _initializeSchema() method to Model\Table class to make id ulid type
...
use Cake\Database\Schema\TableSchemaInterface;
...
class XXXXXXXXTable extends Table
{
    protected function _initializeSchema(TableSchemaInterface $table): TableSchemaInterface
    {
        parent::_initializeSchema($table);
        $table->setColumnType('id', 'ulid'); // set ulid type for id

        return $table;
    }
}
...

Or, you can use a trait.

...
use PrefixUlidType\PrefixUlidTypeTrait;
...
class XXXXXXXXTable extends Table
{
    use PrefixUlidTypeTrait;
}
...

If you want to use _initializeSchema function in your model, you need to call the _traitInitSchema function.

...
use Cake\Database\Schema\TableSchemaInterface;
use PrefixUlidType\PrefixUlidTypeTrait;
...
class XXXXXXXXTable extends Table
{
    use PrefixUlidTypeTrait;

    protected function _initializeSchema(TableSchemaInterface $table): TableSchemaInterface
    {
        parent::_traitInitSchema($table);
        $table->setColumnType('code', 'char'); // set any type for property

        return $table;
    }
}
...