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

Revision #14 has been created by grigori on Nov 25, 2019, 11:40:34 PM with the memo:

added a unique validator
« previous (#13) next (#15) »

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

[...]
{
private $idText;

```

Step 2. Add two
validators and a filters

```php
[...]
return pack("H*", str_replace('-', '', $uuid));
}],
```
 
These filters will validate input,
//now let's check if ID is taken
 
['id','unique','filter'=>function(\yii\db\Query $q){$q->where(['id'=>$this->getAttribute('id')]);}],
 
```
 
 
First rule is a validator for an input. Second rule is a filter
prepareing UUID to be written in a binary format and keeping the text form for output. Third one is a validator running a query over the binary value generated by a filter.
 
We can write a query to validate data, not to save it.


Step 3. Add getters

```php
public function __get($name)
[...]
4 0
3 followers
Viewed: 21 945 times
Version: 2.0
Category: How-tos
Written by: grigori
Last updated by: samdark
Created on: Nov 25, 2019
Last updated: 7 months ago
Update Article

Revisions

View all history