Class ForeignKey
ForeignKey metadata object
Models a database foreign key constraint
Constants
-
CASCADE ¶
'cascade' -
stringCHECK ¶TableSchema::CONSTRAINT_CHECK -
DEFERRED ¶
'DEFERRABLE INITIALLY DEFERRED' -
stringFOREIGN ¶TableSchema::CONSTRAINT_FOREIGN -
IMMEDIATE ¶
'DEFERRABLE INITIALLY IMMEDIATE' -
NOT_DEFERRED ¶
'NOT DEFERRABLE' -
NO_ACTION ¶
'noAction' -
stringPRIMARY ¶TableSchema::CONSTRAINT_PRIMARY -
RESTRICT ¶
'restrict' -
SET_DEFAULT ¶
'setDefault' -
SET_NULL ¶
'setNull' -
stringUNIQUE ¶TableSchema::CONSTRAINT_UNIQUE
Property Summary
-
$deferrable protected
string|null -
$delete protected
?stringThe action to take when the referenced row is deleted.
-
$update protected
?stringThe action to take when the referenced row is updated.
-
$validActions protected
array<string>An allow list of valid actions
Method Summary
-
__construct() public
Constructor
-
getColumns() public
Gets the constraint columns.
-
getDeferrable() public
Gets deferrable mode for the foreign key.
-
getDelete() public
Gets ON DELETE action for the foreign key.
-
getName() public
Gets the constraint name.
-
getReferencedColumns() public
Gets the foreign key referenced columns.
-
getReferencedTable() public
Gets the foreign key referenced table.
-
getType() public
Gets the constraint type.
-
getUpdate() public
Gets ON UPDATE action for the foreign key.
-
normalizeAction() protected
From passed value checks if it's correct and fixes if needed
-
normalizeDeferrable() protected
From passed value checks if it's correct and fixes if needed
-
setColumns() public
Sets the constraint columns.
-
setDeferrable() public
Sets deferrable mode for the foreign key.
-
setDelete() public
Sets ON DELETE action for the foreign key.
-
setName() public
Sets the constraint name.
-
setReferencedColumns() public
Sets the foreign key referenced columns.
-
setReferencedTable() public
Sets the foreign key referenced table.
-
setType() public
Sets the constraint type.
-
setUpdate() public
Sets ON UPDATE action for the foreign key.
-
toArray() public
Converts the foreign key to an array that is compatible with the constructor.
Method Detail
__construct() ¶ public
__construct(string $name, array<string> $columns, ?string $referencedTable = null, array<string> $referencedColumns = [], ?string $delete = null, ?string $update = null, ?string $deferrable = null)
Constructor
Parameters
-
string$name The name of the index.
-
array<string>$columns The columns to index.
-
?string$referencedTable optional The columns to index.
-
array<string>$referencedColumns optional The columns in $referencedTable that this key references.
-
?string$delete optional The action to take when the referenced row is deleted.
-
?string$update optional The action to take when the referenced row is updated.
-
?string$deferrable optional
getColumns() ¶ public
getColumns(): ?array<string>
Gets the constraint columns.
Returns
?array<string>getDeferrable() ¶ public
getDeferrable(): ?string
Gets deferrable mode for the foreign key.
Returns
?stringgetDelete() ¶ public
getDelete(): string|null
Gets ON DELETE action for the foreign key.
Returns
string|nullgetReferencedColumns() ¶ public
getReferencedColumns(): array<string>
Gets the foreign key referenced columns.
Returns
array<string>getReferencedTable() ¶ public
getReferencedTable(): ?string
Gets the foreign key referenced table.
Returns
?stringgetUpdate() ¶ public
getUpdate(): string|null
Gets ON UPDATE action for the foreign key.
Returns
string|nullnormalizeAction() ¶ protected
normalizeAction(string $action): string
From passed value checks if it's correct and fixes if needed
Parameters
-
string$action Action
Returns
stringThrows
InvalidArgumentExceptionnormalizeDeferrable() ¶ protected
normalizeDeferrable(string $deferrable): string
From passed value checks if it's correct and fixes if needed
Parameters
-
string$deferrable Deferrable
Returns
stringThrows
InvalidArgumentExceptionsetColumns() ¶ public
setColumns(array<string>|string $columns): $this
Sets the constraint columns.
Parameters
-
array<string>|string$columns Columns
Returns
$thissetDeferrable() ¶ public
setDeferrable(string $deferrable): $this
Sets deferrable mode for the foreign key.
Parameters
-
string$deferrable Constraint
Returns
$thissetDelete() ¶ public
setDelete(string $delete): $this
Sets ON DELETE action for the foreign key.
Parameters
-
string$delete On Delete
Returns
$thissetName() ¶ public
setName(string $name): $this
Sets the constraint name.
Parameters
-
string$name Name
Returns
$thissetReferencedColumns() ¶ public
setReferencedColumns(array<string>|string $referencedColumns): $this
Sets the foreign key referenced columns.
Parameters
-
array<string>|string$referencedColumns Referenced columns
Returns
$thissetReferencedTable() ¶ public
setReferencedTable(string $table): $this
Sets the foreign key referenced table.
Parameters
-
string$table The table this KEY is pointing to
Returns
$thissetType() ¶ public
setType(string $type): $this
Sets the constraint type.
Parameters
-
string$type Type
Returns
$thissetUpdate() ¶ public
setUpdate(string $update): $this
Sets ON UPDATE action for the foreign key.
Parameters
-
string$update On Update
Returns
$thistoArray() ¶ public
toArray(): array<string, mixed>
Converts the foreign key to an array that is compatible with the constructor.
Returns
array<string, mixed>