-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRelationship.php
More file actions
125 lines (114 loc) · 3.31 KB
/
Relationship.php
File metadata and controls
125 lines (114 loc) · 3.31 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
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
<?php
namespace Utopia\Migration\Resources\Database\Columns;
use Utopia\Database\Database;
use Utopia\Migration\Resources\Database\Column;
use Utopia\Migration\Resources\Database\Table;
class Relationship extends Column
{
public function __construct(
string $key,
Table $table,
string $relatedTable,
string $relationType,
bool $twoWay = false,
?string $twoWayKey = null,
string $onDelete = Database::RELATION_MUTATE_RESTRICT,
string $side = Database::RELATION_SIDE_PARENT,
string $createdAt = '',
string $updatedAt = ''
) {
parent::__construct(
$key,
$table,
options: [
'relatedCollection' => $relatedTable,
'relationType' => $relationType,
'twoWay' => $twoWay,
'twoWayKey' => $twoWayKey,
'onDelete' => $onDelete,
'side' => $side,
],
createdAt: $createdAt,
updatedAt: $updatedAt
);
}
/**
* @param array{
* key: string,
* collection?: array{
* database: array{
* id: string,
* name: string,
* },
* name: string,
* id: string,
* documentSecurity: bool,
* permissions: ?array<string>
* },
* table?: array{
* database: array{
* id: string,
* name: string,
* },
* name: string,
* id: string,
* rowSecurity: bool,
* permissions: ?array<string>
* },
* options: array{
* relatedCollection: string,
* relationType: string,
* twoWay: bool,
* twoWayKey: ?string,
* onDelete: string,
* side: string,
* },
* createdAt: string,
* updatedAt: string,
* } $array
* @return self
*/
public static function fromArray(array $array): self
{
return new self(
$array['key'],
Table::fromArray($array['table'] ?? $array['collection']),
relatedTable: $array['options']['relatedCollection'],
relationType: $array['options']['relationType'],
twoWay: $array['options']['twoWay'],
twoWayKey: $array['options']['twoWayKey'],
onDelete: $array['options']['onDelete'],
side: $array['options']['side'],
createdAt: $array['createdAt'] ?? '',
updatedAt: $array['updatedAt'] ?? '',
);
}
public function getType(): string
{
return Column::TYPE_RELATIONSHIP;
}
public function getRelatedTable(): string
{
return $this->options['relatedCollection'];
}
public function getRelationType(): string
{
return $this->options['relationType'];
}
public function getTwoWay(): bool
{
return $this->options['twoWay'];
}
public function getTwoWayKey(): ?string
{
return $this->options['twoWayKey'];
}
public function getOnDelete(): string
{
return $this->options['onDelete'];
}
public function getSide(): string
{
return $this->options['side'];
}
}