Revision #9 was created by grigori on Nov 25, 2019, 10:50:00 PM.
fixing the markup
Content
[...]
Adding `getId()`/`setId()` won't help - data comes from a client in JSON and fills the model object with a `setAttributes()` call avoiding generic magic methods.
Here's the hack:
Step 1. Add a `private $idText;` property
```php
use yii\db\ActiveRecord;
class Video extends ActiveRecord
{
private $idText;
[...]
From the other hand, the first valiator calls `$model->id` triggering the getter before the UUID is saved to the private property so I need to serve the value from user input.
It is strange to mutate data in a validator, but I found this is the only solution. I belive I shouldn't use `beforeSave()` callback to set the binary value for SQL, and return the text value back in `afterSave()`, supporting this code later will be a hell.
So, now you can go the generic mysqlMySQL way
Step 4. add a virtual column
```sql
ALTER TABLE t1 ADD id_text varchar(36) generated always as