Difference between #1 and #2 of
UUID instead of an auto-increment integer for ID with Active Record

Revision #2 has been created by grigori on Nov 25, 2019, 10:12:48 PM with the memo:

fixing the markup
« previous (#1) next (#3) »

Changes

Title unchanged

UUID instead of an auto-increment integer for ID with Active Record

Category unchanged

How-tos

Yii version unchanged

2.0

Tags changed

mysql,active record,REST,UUID

Content changed

[...]
}],
```
These filters will validate input, prepare UUID to be written in a binary format and keep the text form for output.

3. Add getters

 
```
public function __get($name)
{
[...]
return $this->idText ?? $this->getAttribute('id_text');
}

 
```
 
Active Record does not call the getter method if attributes contain the property. It should not be this way, so I return the default component behavior and make ID returned the right way.
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.
[...]
So, now you can go the generic mysql way
4. add a virtual column

 
```
ALTER TABLE t1 ADD id_text varchar(36) generated always as
(insert(
[...]
24,0,'-')
) virtual;
 
 
```
5 0
4 followers
Viewed: 56 711 times
Version: 2.0
Category: How-tos
Written by: grigori
Last updated by: samdark
Created on: Nov 25, 2019
Last updated: 4 years ago
Update Article

Revisions

View all history