classForeignKey
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.
$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> $columnspublic ForeignKeyClause $clausepublic Deferrability|null $deferrability = nullMethods§
public function __construct(
list<ListedColumn> $columns,
public ForeignKeyClause $clause,
public Deferrability|null $deferrability = null,
)Parameters
$columns | list<ListedColumn> | The child columns in written order; at least one |
$clause | ForeignKeyClause | The parent, its key columns and the actions |
$deferrability | Deferrability|null | The written DEFERRABLE clause |
Calls 2
- static-call Check::listOf() line 49
- class-const ListedColumn::class() line 49
public function deriveConstraint(Derivation $derivation, ConstraintScope $scope): voidReports child columns that the table does not have or that are decorated, then derives the parent clause.
Parameters
$derivation | Derivation | |
$scope | ConstraintScope |
Calls 5
- method-call Derivation::report() line 59
- new DecoratedColumnName line 59
- method-call ConstraintScope::lacks() line 61
- new UnknownColumn line 62
- method-call ForeignKeyClause::deriveConstraint() line 65
public function render(Output $out): voidTest cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.