protected function beforeValidate() { if (parent::beforeValidate() === false) { return false; } if ($this->isNewRecord) { do { $uuid = $this->generateUuid(); $user = Users::model()->find('uuid=?', [$uuid]); } while ($user != null); $this->uuid = $uuid; } return true; }