yii-gii icon indicating copy to clipboard operation
yii-gii copied to clipboard

Simple property mapper for ActiveRecord.

Open mj4444ru opened this issue 3 years ago • 7 comments

It would be great if the generated ActiveRecord had a property mapper. That is, create_at was mapped to createAt. For example like this:

public function getAttributeMap(): array
{
    return [
        'createAt' => 'create_at',
    ];
}

public function __get(string $name)
{
    return parent::__get($this->getAttributeMap()[$name] ?? $name);
}

public function __set(string $name, $value): void
{
    parent::__set($this->getAttributeMap()[$name] ?? $name, $value);
}

public function __isset(string $name): bool
{
    return parent::__isset($this->getAttributeMap()[$name] ?? $name);
}

public function __unset(string $name): void
{
    return parent::__unset($this->getAttributeMap()[$name] ?? $name);
}

@property will be appropriate.

mj4444ru avatar Oct 20 '20 00:10 mj4444ru