فهرست منبع

add ramsey/uuid-doctrine and update AbstractMessage::uuid definition

Olivier Massot 2 سال پیش
والد
کامیت
48ca1a4884
3فایلهای تغییر یافته به همراه11 افزوده شده و 1 حذف شده
  1. 1 0
      composer.json
  2. 2 0
      config/packages/doctrine.yaml
  3. 8 1
      src/Entity/Message/AbstractMessage.php

+ 1 - 0
composer.json

@@ -31,6 +31,7 @@
         "odolbeau/phone-number-bundle": "^3.1",
         "phpdocumentor/reflection-docblock": "^5.2",
         "ramsey/uuid": "^4.2",
+        "ramsey/uuid-doctrine": "^2.0",
         "symfony/asset": "6.2.*",
         "symfony/console": "6.2.*",
         "symfony/doctrine-messenger": "6.2.*",

+ 2 - 0
config/packages/doctrine.yaml

@@ -20,6 +20,8 @@ doctrine:
                 # IMPORTANT: You MUST configure your server version,
                 # either here or in the DATABASE_URL env var (see .env file)
                 server_version: '5.7'
+        types:
+            uuid: Ramsey\Uuid\Doctrine\UuidType
 
     orm:
         default_entity_manager: default

+ 8 - 1
src/Entity/Message/AbstractMessage.php

@@ -8,7 +8,9 @@ use App\Entity\Organization\Organization;
 use App\Enum\Message\MessageStatusEnum;
 use Doctrine\ORM\Mapping as ORM;
 use Ramsey\Uuid\UuidInterface;
+use Ramsey\Uuid\Doctrine\UuidGenerator;
 use Symfony\Component\Validator\Constraints as Assert;
+use Symfony\Bridge\Doctrine\Types\UuidType;
 
 /**
  * Classe ... qui ...
@@ -22,7 +24,12 @@ abstract class AbstractMessage
     #[ORM\GeneratedValue]
     protected ?int $id = null;
 
-    #[ORM\Column(type: 'string', unique: true)]
+    /**
+     * @var UuidInterface|null
+     */
+    #[ORM\Column(type: "uuid", unique: true)]
+    #[ORM\GeneratedValue(strategy: "CUSTOM")]
+    #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
     protected ?UuidInterface $uuid = null;
 
     #[ORM\ManyToOne]