ForeignKeyDefinition.php
115 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Defines a foreign key constraint with configurable ON UPDATE and ON DELETE actions. |
| 5 | * Links local and referenced columns while expressing referential integrity rules in schema migrations. |
| 6 | * Integrates with the structure builder when declaring relational table constraints. |
| 7 | * Allows setting actions such as CASCADE, RESTRICT, SET NULL, and NO ACTION for both update and delete events. |
| 8 | * |
| 9 | * @package Framework |
| 10 | * @subpackage Database\Schema\Definitions |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | namespace Kirki\Framework\Database\Schema\Definitions; |
| 14 | |
| 15 | \defined('ABSPATH') || exit; |
| 16 | /** |
| 17 | * Define the foreign key constraint of the database schema. |
| 18 | * |
| 19 | * @method $this on(string $table) |
| 20 | * @method $this on_update(string $action) |
| 21 | * @method $this on_delete(string $action) |
| 22 | * @method $this references(string $references) |
| 23 | */ |
| 24 | class ForeignKeyDefinition extends Definition |
| 25 | { |
| 26 | /** |
| 27 | * Set ON UPDATE action to CASCADE. |
| 28 | * |
| 29 | * @return $this |
| 30 | * |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | public function cascade_on_update() |
| 34 | { |
| 35 | return $this->on_update('cascade'); |
| 36 | } |
| 37 | /** |
| 38 | * Set ON DELETE action to CASCADE. |
| 39 | * |
| 40 | * @return $this |
| 41 | * |
| 42 | * @since 1.0.0 |
| 43 | */ |
| 44 | public function cascade_on_delete() |
| 45 | { |
| 46 | return $this->on_delete('cascade'); |
| 47 | } |
| 48 | /** |
| 49 | * Set ON UPDATE action to RESTRICT. |
| 50 | * |
| 51 | * @return $this |
| 52 | * |
| 53 | * @since 1.0.0 |
| 54 | */ |
| 55 | public function restrict_on_update() |
| 56 | { |
| 57 | return $this->on_update('restrict'); |
| 58 | } |
| 59 | /** |
| 60 | * Set ON DELETE action to RESTRICT. |
| 61 | * |
| 62 | * @return $this |
| 63 | * |
| 64 | * @since 1.0.0 |
| 65 | */ |
| 66 | public function restrict_on_delete() |
| 67 | { |
| 68 | return $this->on_delete('restrict'); |
| 69 | } |
| 70 | /** |
| 71 | * Set ON UPDATE action to SET NULL. |
| 72 | * |
| 73 | * @return $this |
| 74 | * |
| 75 | * @since 1.0.0 |
| 76 | */ |
| 77 | public function null_on_update() |
| 78 | { |
| 79 | return $this->on_update('set null'); |
| 80 | } |
| 81 | /** |
| 82 | * Set ON DELETE action to SET NULL. |
| 83 | * |
| 84 | * @return $this |
| 85 | * |
| 86 | * @since 1.0.0 |
| 87 | */ |
| 88 | public function null_on_delete() |
| 89 | { |
| 90 | return $this->on_delete('set null'); |
| 91 | } |
| 92 | /** |
| 93 | * Set ON UPDATE action to NO ACTION. |
| 94 | * |
| 95 | * @return $this |
| 96 | * |
| 97 | * @since 1.0.0 |
| 98 | */ |
| 99 | public function no_action_on_update() |
| 100 | { |
| 101 | return $this->on_update('no action'); |
| 102 | } |
| 103 | /** |
| 104 | * Set ON DELETE action to NO ACTION. |
| 105 | * |
| 106 | * @return $this |
| 107 | * |
| 108 | * @since 1.0.0 |
| 109 | */ |
| 110 | public function no_action_on_delete() |
| 111 | { |
| 112 | return $this->on_delete('no action'); |
| 113 | } |
| 114 | } |
| 115 |