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.

Reading a foreign keydoctest
$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> $columns
public list<Name> $referenced
public list<ReferentialAction> $actions
public list<ConstraintAttribute> $attributes
public QualifiedName $table
public KeyMatch|null $match = null
public Name|null $name = null

Methods§

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

$columnslist<Name>The referencing columns; at least one
$tableQualifiedNameThe referenced table
$referencedlist<Name>The referenced columns
$matchKeyMatch|nullThe match type, when written
$actionslist<ReferentialAction>The ON UPDATE and ON DELETE clauses, in the order written
$attributeslist<ConstraintAttribute>The attributes in the order written
$nameName|nullThe constraint name
Calls 6
public function kind(): ConstraintKind

Answers the kind of the constraint.

Calls 1
public function deriveClause(Derivation $derivation, Environment $environment): void

Checks the referencing columns, resolves the referenced table and checks the attributes.

Parameters

$derivationDerivation
$environmentEnvironment
Calls 9
public function render(Output $out): void

Test cases 1§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 1

Relations§

Instantiated in 1
Constant reads 1