1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cycle\Annotated\Annotation\Relation; |
6
|
|
|
|
7
|
|
|
use Cycle\Annotated\Annotation\Relation\Traits\InverseTrait; |
8
|
|
|
use Doctrine\Common\Annotations\Annotation\Enum; |
9
|
|
|
use JetBrains\PhpStorm\ExpectedValues; |
10
|
|
|
use Spiral\Attributes\NamedArgumentConstructor; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @Annotation |
14
|
|
|
* @NamedArgumentConstructor |
15
|
|
|
* @Target("PROPERTY") |
16
|
|
|
*/ |
17
|
|
|
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor] |
18
|
|
|
final class BelongsTo extends Relation |
19
|
|
|
{ |
20
|
|
|
use InverseTrait; |
21
|
|
|
|
22
|
|
|
protected const TYPE = 'belongsTo'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param non-empty-string $target |
|
|
|
|
26
|
|
|
* @param array|non-empty-string|null $innerKey Inner key in source entity. Defaults to {relationName}_{outerKey}. |
27
|
|
|
* @param array|non-empty-string|null $outerKey Outer key in the related entity. Defaults to the primary key. |
28
|
|
|
* @param bool $cascade Automatically save related data with source entity. |
29
|
|
|
* @param bool $nullable Defines if the relation can be nullable (child can have no parent). |
30
|
|
|
* @param bool $fkCreate Set to true to automatically create FK on innerKey. |
31
|
|
|
* @param non-empty-string $fkAction FK onDelete and onUpdate action. |
32
|
|
|
* @param non-empty-string|null $fkOnDelete FK onDelete action. It has higher priority than {@see $fkAction}. |
33
|
|
|
* Defaults to {@see $fkAction}. |
34
|
|
|
* @param bool $indexCreate Create an index on innerKey. |
35
|
|
|
* @param non-empty-string $load Relation load approach. |
36
|
|
|
*/ |
37
|
616 |
|
public function __construct( |
38
|
|
|
string $target, |
39
|
|
|
protected array|string|null $innerKey = null, |
40
|
|
|
protected array|string|null $outerKey = null, |
41
|
|
|
protected bool $cascade = true, |
42
|
|
|
protected bool $nullable = false, |
43
|
|
|
protected bool $fkCreate = true, |
44
|
|
|
/** |
45
|
|
|
* @Enum({"NO ACTION", "CASCADE", "SET NULL"}) |
46
|
|
|
*/ |
47
|
|
|
#[ExpectedValues(values: ['NO ACTION', 'CASCADE', 'SET NULL'])] |
48
|
|
|
protected string $fkAction = 'CASCADE', |
49
|
|
|
/** |
50
|
|
|
* @Enum({"NO ACTION", "CASCADE", "SET NULL"}) |
51
|
|
|
*/ |
52
|
|
|
#[ExpectedValues(values: ['NO ACTION', 'CASCADE', 'SET NULL'])] |
53
|
|
|
protected ?string $fkOnDelete = null, |
54
|
|
|
protected bool $indexCreate = true, |
55
|
|
|
#[ExpectedValues(values: ['lazy', 'eager'])] |
56
|
|
|
string $load = 'lazy', |
57
|
|
|
?Inverse $inverse = null |
58
|
|
|
) { |
59
|
616 |
|
$this->inverse = $inverse; |
60
|
|
|
|
61
|
616 |
|
parent::__construct($target, $load); |
62
|
616 |
|
} |
63
|
|
|
} |
64
|
|
|
|