Skip to content

Commit fcfcd9e

Browse files
committed
chore: allow setting foreign key as deferred
1 parent 4664373 commit fcfcd9e

File tree

6 files changed

+11
-2
lines changed

6 files changed

+11
-2
lines changed

docs/en/reference/attributes-reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ Optional parameters:
677677
affected entities and should be enforced as such on the database
678678
constraint level. Defaults to false.
679679
- **deferrable**: Determines whether this relation constraint can be deferred. Defaults to false.
680+
- **deferred**: Determines whether this deferrable relation constraint can be IMMEDIATE or DEFERRED. Defaults to false (IMMEDIATE).
680681
- **nullable**: Determine whether the related entity is required, or if
681682
null is an allowed state for the relation. Defaults to true.
682683
- **onDelete**: Cascade Action (Database-level)

src/Mapping/Driver/AttributeDriver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ private function joinColumnToArray(Mapping\JoinColumn|Mapping\InverseJoinColumn
685685
$mapping = [
686686
'name' => $joinColumn->name,
687687
'deferrable' => $joinColumn->deferrable,
688+
'deferred' => $joinColumn->deferrable,
688689
'unique' => $joinColumn->unique,
689690
'nullable' => $joinColumn->nullable,
690691
'onDelete' => $joinColumn->onDelete,

src/Mapping/JoinColumnMapping.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class JoinColumnMapping implements ArrayAccess
1414
use ArrayAccessImplementation;
1515

1616
public bool|null $deferrable = null;
17+
public bool|null $deferred = null;
1718
public bool|null $unique = null;
1819
public bool|null $quoted = null;
1920
public string|null $fieldName = null;
@@ -67,7 +68,7 @@ public function __sleep(): array
6768
}
6869
}
6970

70-
foreach (['deferrable', 'unique', 'quoted', 'nullable'] as $boolKey) {
71+
foreach (['deferrable', 'deferred', 'unique', 'quoted', 'nullable'] as $boolKey) {
7172
if ($this->$boolKey !== null) {
7273
$serialized[] = $boolKey;
7374
}

src/Mapping/JoinColumnProperties.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function __construct(
1111
public readonly string|null $name = null,
1212
public readonly string|null $referencedColumnName = null,
1313
public readonly bool $deferrable = false,
14+
public readonly bool $deferred = false,
1415
public readonly bool $unique = false,
1516
public readonly bool $nullable = true,
1617
public readonly mixed $onDelete = null,

src/Tools/SchemaTool.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ private function gatherRelationJoinColumns(
722722
if (isset($joinColumn->deferrable)) {
723723
$fkOptions['deferrable'] = $joinColumn->deferrable;
724724
}
725+
726+
if (isset($joinColumn->deferrable)) {
727+
$fkOptions['deferred'] = $joinColumn->deferred;
728+
}
725729
}
726730

727731
// Prefer unique constraints over implicit simple indexes created for foreign keys.

tests/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function testSetDeferrableForeignKey(): void
5656
self::assertCount(1, $fks);
5757

5858
self::assertTrue($fks[0]->getOption('deferrable'));
59+
self::assertTrue($fks[0]->getOption('deferred'));
5960
}
6061
}
6162

@@ -127,6 +128,6 @@ class EntityWithSelfReferencingAssociation
127128
private int $id;
128129

129130
#[ManyToOne(targetEntity: self::class)]
130-
#[JoinColumn(deferrable: true)]
131+
#[JoinColumn(deferrable: true, deferred: true)]
131132
private self $parent;
132133
}

0 commit comments

Comments
 (0)