forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DDC964User.php
144 lines (125 loc) · 4.08 KB
/
DDC964User.php
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
namespace Doctrine\Tests\Models\DDC964;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\InverseJoinColumn;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\MappedSuperclass;
#[MappedSuperclass]
class DDC964User
{
/** @var int */
#[Id]
#[GeneratedValue]
#[Column(type: 'integer', name: 'user_id', length: 150)]
protected $id;
/** @psalm-var Collection<int, DDC964Group> */
#[ManyToMany(targetEntity: DDC964Group::class, inversedBy: 'users', cascade: ['persist', 'detach'])]
#[JoinTable(name: 'ddc964_users_groups')]
#[JoinColumn(name: 'user_id', referencedColumnName: 'id')]
#[InverseJoinColumn(name: 'group_id', referencedColumnName: 'id')]
protected $groups;
/** @var DDC964Address */
#[ManyToOne(targetEntity: DDC964Address::class, cascade: ['persist'])]
#[JoinColumn(name: 'address_id', referencedColumnName: 'id')]
protected $address;
public function __construct(
#[Column(name: 'user_name', nullable: true, unique: false, length: 250)]
protected string|null $name = null,
) {
$this->groups = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function getName(): string|null
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function addGroup(DDC964Group $group): void
{
$this->groups->add($group);
$group->addUser($this);
}
/** @psalm-return Collection<int, DDC964Group> */
public function getGroups(): ArrayCollection
{
return $this->groups;
}
public function getAddress(): DDC964Address
{
return $this->address;
}
public function setAddress(DDC964Address $address): void
{
$this->address = $address;
}
public static function loadMetadata(ClassMetadata $metadata): void
{
$metadata->isMappedSuperclass = true;
$metadata->mapField(
[
'id' => true,
'fieldName' => 'id',
'type' => 'integer',
'columnName' => 'user_id',
'length' => 150,
],
);
$metadata->mapField(
[
'fieldName' => 'name',
'type' => 'string',
'columnName' => 'user_name',
'nullable' => true,
'unique' => false,
'length' => 250,
],
);
$metadata->mapManyToOne(
[
'fieldName' => 'address',
'targetEntity' => 'DDC964Address',
'cascade' => ['persist'],
'joinColumns' => [['name' => 'address_id', 'referencedColumnMame' => 'id']],
],
);
$metadata->mapManyToMany(
[
'fieldName' => 'groups',
'targetEntity' => 'DDC964Group',
'inversedBy' => 'users',
'cascade' => ['persist','detach'],
'joinTable' => [
'name' => 'ddc964_users_groups',
'joinColumns' => [
[
'name' => 'user_id',
'referencedColumnName' => 'id',
],
],
'inverseJoinColumns' => [
[
'name' => 'group_id',
'referencedColumnName' => 'id',
],
],
],
],
);
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
}
}