-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPetMapping.php
More file actions
37 lines (33 loc) · 1.26 KB
/
PetMapping.php
File metadata and controls
37 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace App\Pet\Orm;
use App\Pet\Model\Pet;
use App\Pet\Model\Vaccination;
use Chubbyphp\Laminas\Config\Doctrine\Persistence\Mapping\Driver\ClassMapMappingInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadata;
final class PetMapping implements ClassMapMappingInterface
{
/**
* @param ClassMetadata<Pet> $metadata
*/
public function configureMapping(ClassMetadata $metadata): void
{
/** @var ORMClassMetadata<Pet> $metadata */
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable('pet');
$builder->createField('id', Types::GUID)->makePrimaryKey()->build();
$builder->addField('createdAt', Types::DATETIME_IMMUTABLE);
$builder->addField('updatedAt', Types::DATETIME_IMMUTABLE, ['nullable' => true]);
$builder->addField('name', Types::STRING);
$builder->addField('tag', Types::STRING, ['nullable' => true]);
$builder->createOneToMany('vaccinations', Vaccination::class)
->mappedBy('pet')
->cascadeAll()
->orphanRemoval()
->build()
;
}
}