final class ForeignKey
    implements TableConstraint
    uses Snapshot
Public API: explicitly declared with @visibility public.

A FOREIGN KEY table constraint.

Rule: SQLITE-TABLE-FOREIGN-KEY-001. The child columns are columns of the table being defined; a name that is none is reported ("unknown column in

  • foreign key definition"), and so is a child column written with a collation

or a sort order. The parent is not looked up when the table is defined. Source: https://sqlite.org/foreignkeys.html. Status: Implemented.

Reading a composite foreign keydoctest
$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE c (a, b, FOREIGN KEY (a, b) REFERENCES parent (x, y) DEFERRABLE INITIALLY DEFERRED)');
    $key = $create->statement->constraints[0]->items[0];
    [count($key->columns), $key->clause->table->value, $key->deferrability?->deferred()] // => [2, 'parent', true]

Properties§

public non-empty-list<ListedColumn> $columns
public Deferrability|null $deferrability = null

Methods§

public function __construct(
    list<ListedColumn> $columns,
    public ForeignKeyClause $clause,
    public Deferrability|null $deferrability = null,
)

Parameters

$columnslist<ListedColumn>The child columns in written order; at least one
$clauseForeignKeyClauseThe parent, its key columns and the actions
$deferrabilityDeferrability|nullThe written DEFERRABLE clause
Calls 2
public function deriveConstraint(Derivation $derivation, ConstraintScope $scope): void

Reports child columns that the table does not have or that are decorated, then derives the parent clause.

Parameters

$derivationDerivation
$scopeConstraintScope
Calls 5
public function render(Output $out): void

Writes the clause.

Parameters

$outOutput
Calls 1

Test cases 3§

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

Dedicated tests 1
Other tests reaching this symbol 2

Relations§

Instantiated in 1