cycle /
annotated
| 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 HasOne extends Relation |
||
| 19 | { |
||
| 20 | use InverseTrait; |
||
| 21 | |||
| 22 | protected const TYPE = 'hasOne'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param non-empty-string $target |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 26 | * @param array|non-empty-string|null $innerKey Inner key in parent entity. Defaults to primary key. |
||
| 27 | * @param array|non-empty-string|null $outerKey Outer key name. Defaults to {parentRole}_{innerKey}. |
||
| 28 | * @param bool $cascade Automatically save related data with parent entity. |
||
| 29 | * @param bool $nullable Defines if relation can be nullable (child can have no parent). |
||
| 30 | * @param bool $fkCreate Set to true to automatically create FK on outerKey. |
||
| 31 | * @param non-empty-string|null $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 index on outerKey. |
||
| 35 | * @param non-empty-string $load Relation load approach. |
||
| 36 | */ |
||
| 37 | 712 | 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 | 712 | $this->inverse = $inverse; |
|
| 60 | |||
| 61 | 712 | parent::__construct($target, $load); |
|
| 62 | 712 | } |
|
| 63 | } |
||
| 64 |