classForeignKeys
final class ForeignKeys
Derives and writes the referenced side of a foreign key.
Rule: PG-FOREIGN-KEY-001. The referenced table is resolved by PG-TABLE-TARGET-001 and recorded as the relation facts of the constraint; a relation declared as another kind than a table is reported (PG-RELATION-KIND-001: referenced relation "%s" is not a table). When its column list is complete, a referenced column it lacks is reported ("column referenced in foreign key constraint does not exist"). At most one ON UPDATE and one ON DELETE clause are written, in either order. MATCH PARTIAL is not implemented by the server, and a SET NULL or SET DEFAULT column list is accepted only for ON DELETE; both are reported. Source: https://www.postgresql.org/docs/17/sql-createtable.html#SQL-CREATETABLE-PARMS-REFERENCES. Termination: one pass over the columns and actions. Status: Implemented.
Methods§
public function actions(list<ReferentialAction> $actions): list<ReferentialAction>Checks the referential actions: at most one per event.
Parameters
$actions | list<ReferentialAction> |
Returns
list<ReferentialAction>Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Column\References::__construct() packages/sql-semantics-postgres/src/Statement/Constraint/Column/References.php:60
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Table\ForeignKey::__construct() packages/sql-semantics-postgres/src/Statement/Constraint/Table/ForeignKey.php:76
Calls 4
- static-call Check::listOf() line 50
- class-const ReferentialAction::class() line 50
- static-call Check::input() line 51
- function-call
countline 51
public function derive(
Derivation $derivation,
Node $constraint,
QualifiedName $table,
list<Name> $columns,
?KeyMatch $match,
list<ReferentialAction> $actions,
): voidResolves the referenced table, records it for the constraint and reports what the server rejects.
Parameters
$derivation | Derivation | |
$constraint | Node | |
$table | QualifiedName | |
$columns | list<Name> | The referenced columns |
$match | ?KeyMatch | |
$actions | list<ReferentialAction> |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Column\References::deriveClause() packages/sql-semantics-postgres/src/Statement/Constraint/Column/References.php:76
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Table\ForeignKey::deriveClause() packages/sql-semantics-postgres/src/Statement/Constraint/Table/ForeignKey.php:94
Calls 18
- method-call Derivation::target() line 65
- method-call Targets::resolve() line 65
- new Targets line 65
- new RelationKinds line 66
- method-call RelationKinds::require() line 67
- method-call RelationKinds::of() line 67
- class-const RelationKind::BaseTable() line 67
- class-const KindRule::ReferencedRelation() line 67
- method-call KeyColumns::report() line 71
- new KeyColumns line 71
- class-const DefinitionRule::MissingReferencedColumn() line 71
- class-const KeyMatch::Partial() line 73
- method-call Derivation::report() line 74
- new DefinitionProblem line 74
- class-const DefinitionRule::MatchPartial() line 74
- class-const ReferenceEvent::Update() line 77
- class-const DefinitionRule::SetColumnsOnUpdate() line 78
- new Name line 78
public function writeTarget(
Output $out,
QualifiedName $table,
list<Name> $columns,
?KeyMatch $match,
list<ReferentialAction> $actions,
): voidWrites the referenced table, its columns, the match type and the actions.
Parameters
$out | Output | |
$table | QualifiedName | |
$columns | list<Name> | |
$match | ?KeyMatch | |
$actions | list<ReferentialAction> |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Column\References::render() packages/sql-semantics-postgres/src/Statement/Constraint/Column/References.php:87
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Table\ForeignKey::render() packages/sql-semantics-postgres/src/Statement/Constraint/Table/ForeignKey.php:112
Calls 6
- method-call Spelling::qualified() line 91
- new Spelling line 91
- method-call Writing::parenthesized() line 93
- new Writing line 93
- method-call Output::keyword() line 96
- method-call Output::node() line 99
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 6
- new SqlSemantics\Platform\PostgreSql\Statement\Constraint\Column\References::__construct() packages/sql-semantics-postgres/src/Statement/Constraint/Column/References.php:60
- new SqlSemantics\Platform\PostgreSql\Statement\Constraint\Column\References::deriveClause() packages/sql-semantics-postgres/src/Statement/Constraint/Column/References.php:76
- new SqlSemantics\Platform\PostgreSql\Statement\Constraint\Column\References::render() packages/sql-semantics-postgres/src/Statement/Constraint/Column/References.php:87
- new SqlSemantics\Platform\PostgreSql\Statement\Constraint\Table\ForeignKey::__construct() packages/sql-semantics-postgres/src/Statement/Constraint/Table/ForeignKey.php:76
- new SqlSemantics\Platform\PostgreSql\Statement\Constraint\Table\ForeignKey::deriveClause() packages/sql-semantics-postgres/src/Statement/Constraint/Table/ForeignKey.php:94
- new SqlSemantics\Platform\PostgreSql\Statement\Constraint\Table\ForeignKey::render() packages/sql-semantics-postgres/src/Statement/Constraint/Table/ForeignKey.php:112
Method calls 6
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Column\References::__construct() packages/sql-semantics-postgres/src/Statement/Constraint/Column/References.php:60
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Column\References::deriveClause() packages/sql-semantics-postgres/src/Statement/Constraint/Column/References.php:76
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Column\References::render() packages/sql-semantics-postgres/src/Statement/Constraint/Column/References.php:87
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Table\ForeignKey::__construct() packages/sql-semantics-postgres/src/Statement/Constraint/Table/ForeignKey.php:76
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Table\ForeignKey::deriveClause() packages/sql-semantics-postgres/src/Statement/Constraint/Table/ForeignKey.php:94
- method-call SqlSemantics\Platform\PostgreSql\Statement\Constraint\Table\ForeignKey::render() packages/sql-semantics-postgres/src/Statement/Constraint/Table/ForeignKey.php:112