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

Revision #7 has been created by grigori on Nov 25, 2019, 10:42:23 PM with the memo:

fixing the markup
« previous (#6) next (#8) »

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 unchanged

mysql,active record,REST,UUID

Content changed

[...]
Here's the hack:

Step 1 add a private $idText; property

```
 
class Video extends ActiveRecord
 
{
 
    private $idText;
 
 
```
 
 
Step 2 add two filters

```
[...]
// this is a workaround for lack of mapping in active record
['id','filter','skipOnError'=>true, 'filter'=>function($uuid){
  $this->idText = $uuid;    return pack("H*", str_replace('-', '', $uuid));    }],
```
These filters will validate input, prepare UUID to be written in a binary format and keep the text form for output.
[...]
So, now you can go the generic mysql way

 
Step 4. add a virtual column

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

Revisions

View all history