classForeignKeyClause
final class ForeignKeyClause
implements ColumnConstraint
uses Snapshot
@visibility public.A REFERENCES clause: the parent table of a foreign key, its key columns and the actions.
Rule: SQLITE-FK-CLAUSE-001. Written as a column constraint, the clause makes the column a foreign key of one column. The parent is named without a schema and belongs to the schema of the child table. SQLite does not look the parent up when the table is defined ("the parent table or parent key
- columns do not exist" is found when rows are changed), so the model records
no resolution and no diagnostic for the parent. A parent column written with a collation or a sort order is a syntax error in SQLite and is reported as a diagnostic. Source: https://sqlite.org/foreignkeys.html, https://sqlite.org/syntax/foreign-key-clause.html. Status: Implemented.
$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE c (p REFERENCES parent (id) ON DELETE CASCADE)');
$clause = $create->statement->columns[0]->constraints[0];
[$clause->table->value, $clause->columns[0]->name->value, count($clause->arguments)] // => ['parent', 'id', 1]Properties§
public list<ListedColumn>|null $columnspublic list<ReferenceArgument> $argumentspublic Name $tableMethods§
public function __construct(
public Name $table,
list<ListedColumn>|null $columns = null,
list<ReferenceArgument> $arguments = [],
)Parameters
$table | Name | The parent table |
$columns | list<ListedColumn>|null | The parent key columns; null when none are written, otherwise at least one |
$arguments | list<ReferenceArgument> | The actions and MATCH names in written order |
Calls 3
- static-call Check::listOf() line 59
- class-const ListedColumn::class() line 59
- class-const ReferenceArgument::class() line 60
public function reaction(ReferenceEvent $event): ReferenceReactionAnswers the reaction in effect for an event: that of the last action written for it, or no action.
Parameters
$event | ReferenceEvent |
Returns
Test cases 2
Calls 1
- class-const ReferenceReaction::NoAction() line 68
public function deriveConstraint(Derivation $derivation, ConstraintScope $scope): voidReports parent columns written with a collation or a sort order.
Parameters
$derivation | Derivation | |
$scope | ConstraintScope |
Called from 1
Calls 2
- method-call Derivation::report() line 85
- new DecoratedColumnName line 85
public function render(Output $out): voidWrites the clause.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 95
- class-const NameUse::Relation() line 95
- method-call Output::symbol() line 97
- method-call Output::node() line 100
Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 4
Other tests reaching this symbol 5
ColumnRuleTest::testConstraintLowersEveryKindOfConstraintcallsForeignKeyRuleTest::testArgumentLowersEveryEventAndReactioncallsForeignKeyRuleTest::testArgumentsKeepTheirWrittenOrdercallsForeignKeyRuleTest::testClauseLowersTheParentAndItsOptionalColumnscallsReferenceArgumentTest::testRenderWritesEveryKindOfClauseInWrittenOrdercalls