classForeignKey
final class ForeignKey
implements Constraint
uses Snapshot
Public API: explicitly declared with
@visibility public.A FOREIGN KEY table constraint: the referencing columns hold values of the referenced columns.
Mirrors CONSTR_FOREIGN with fk_attrs, pktable, pk_attrs, fk_matchtype, the actions and the attributes. The referencing columns must be columns of the table; the referenced table is resolved (PG-FOREIGN-KEY-001) and is the relation fact of this constraint. Source: https://www.postgresql.org/docs/17/sql-createtable.html#SQL-CREATETABLE-PARMS-REFERENCES.
$create = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE TABLE t (a int, FOREIGN KEY (a) REFERENCES u (id) MATCH SIMPLE ON DELETE CASCADE ON UPDATE NO ACTION NOT VALID)');
$create->toString() // => 'CREATE TABLE t (a INT, FOREIGN KEY (a) REFERENCES u (id) MATCH SIMPLE ON DELETE CASCADE ON UPDATE NO ACTION NOT VALID)'Properties§
public non-empty-list<Name> $columnspublic list<Name> $referencedpublic list<ReferentialAction> $actionspublic list<ConstraintAttribute> $attributespublic QualifiedName $tablepublic KeyMatch|null $match = nullpublic Name|null $name = nullMethods§
public function __construct(
list<Name> $columns,
public QualifiedName $table,
list<Name> $referenced = [],
public KeyMatch|null $match = null,
list<ReferentialAction> $actions = [],
list<ConstraintAttribute> $attributes = [],
public Name|null $name = null,
)Parameters
$columns | list<Name> | The referencing columns; at least one |
$table | QualifiedName | The referenced table |
$referenced | list<Name> | The referenced columns |
$match | KeyMatch|null | The match type, when written |
$actions | list<ReferentialAction> | The ON UPDATE and ON DELETE clauses, in the order written |
$attributes | list<ConstraintAttribute> | The attributes in the order written |
$name | Name|null | The constraint name |
Calls 6
- static-call Check::listOf() line 74
- class-const Name::class() line 74
- method-call ForeignKeys::actions() line 76
- new ForeignKeys line 76
- method-call Attributes::checked() line 77
- new Attributes line 77
public function kind(): ConstraintKindpublic function deriveClause(Derivation $derivation, Environment $environment): voidChecks the referencing columns, resolves the referenced table and checks the attributes.
Parameters
$derivation | Derivation | |
$environment | Environment |
Calls 9
- method-call KeyClauses::derive() line 93
- new KeyClauses line 93
- method-call ForeignKeys::derive() line 94
- new ForeignKeys line 94
- new GeneratedColumns line 95
- method-call GeneratedColumns::among() line 96
- method-call GeneratedColumns::keyActions() line 97
- method-call Attributes::report() line 99
- new Attributes line 99
public function render(Output $out): voidWrites the constraint.
Parameters
$out | Output |
Calls 7
- new Writing line 107
- method-call Writing::constraintName() line 108
- method-call Output::keyword() line 109
- method-call Writing::parenthesized() line 110
- method-call ForeignKeys::writeTarget() line 112
- new ForeignKeys line 112
- method-call Writing::sequence() line 113
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.