Hello,
I want to use UUID as the id and primary key in my tables/Models.
I tried a database before insert trigger but threw an error. One solution is to use an auto increment id then an additional uuid field I guess.
The other solution I was working on was in the model with beforeValidationOnCreate() but the only way I could find to create a UUID was to setup another connection. Using Models Manager threw a syntax errror
public function beforeValidationOnCreate()
{
//Db credentials
$db_config = array(
"host" => "localhost",
"username" => "xxx",
"password" => "xxx",
"dbname" => "xxx"
);
// Create a connection
$this->conn = new \Phalcon\Db\Adapter\Pdo\Mysql($db_config);
try {
$query = $this->conn->query("SELECT UUID()");
$result = $query->fetch();
$this->id = $result[0];
$this->date_entered = date('Y-m-d H:i:s');
} catch (PDOException $e) {
print_r($e->getMessage());
}
}
While this works and I can use in a base model class and extend the ohters it seems like there should be a better way. Any ideas?
Thanks