Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/reference/attributes-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ Optional parameters:
affected entities and should be enforced as such on the database
constraint level. Defaults to false.
- **deferrable**: Determines whether this relation constraint can be deferred. Defaults to false.
- **deferred**: Determines whether this deferrable relation constraint can be INITIALLY IMMEDIATE or INITIALLY DEFERRED. Defaults to false (INITIALLY IMMEDIATE).
- **nullable**: Determine whether the related entity is required, or if
null is an allowed state for the relation. Defaults to true.
- **onDelete**: Cascade Action (Database-level)
Expand Down
1 change: 1 addition & 0 deletions src/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ private function joinColumnToArray(Mapping\JoinColumn|Mapping\InverseJoinColumn
$mapping = [
'name' => $joinColumn->name,
'deferrable' => $joinColumn->deferrable,
'deferred' => $joinColumn->deferred,
'unique' => $joinColumn->unique,
'nullable' => $joinColumn->nullable,
'onDelete' => $joinColumn->onDelete,
Expand Down
3 changes: 2 additions & 1 deletion src/Mapping/JoinColumnMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class JoinColumnMapping implements ArrayAccess
use ArrayAccessImplementation;

public bool|null $deferrable = null;
public bool|null $deferred = null;
public bool|null $unique = null;
public bool|null $quoted = null;
public string|null $fieldName = null;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function __sleep(): array
}
}

foreach (['deferrable', 'unique', 'quoted', 'nullable'] as $boolKey) {
foreach (['deferrable', 'deferred', 'unique', 'quoted', 'nullable'] as $boolKey) {
if ($this->$boolKey !== null) {
$serialized[] = $boolKey;
}
Expand Down
1 change: 1 addition & 0 deletions src/Mapping/JoinColumnProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public function __construct(
public readonly string|null $name = null,
public readonly string|null $referencedColumnName = null,
public readonly bool $deferrable = false,
public readonly bool $deferred = false,
public readonly bool $unique = false,
public readonly bool|null $nullable = null,
public readonly mixed $onDelete = null,
Expand Down
4 changes: 4 additions & 0 deletions src/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@ private function gatherRelationJoinColumns(
if (isset($joinColumn->deferrable)) {
$fkOptions['deferrable'] = $joinColumn->deferrable;
}

if (isset($joinColumn->deferred)) {
$fkOptions['deferred'] = $joinColumn->deferred;
}
}

// Prefer unique constraints over implicit simple indexes created for foreign keys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function testSetDeferrableForeignKey(): void
self::assertCount(1, $fks);

self::assertTrue($fks[0]->getOption('deferrable'));
self::assertTrue($fks[0]->getOption('deferred'));
}
}

Expand Down Expand Up @@ -127,6 +128,6 @@ class EntityWithSelfReferencingAssociation
private int $id;

#[ManyToOne(targetEntity: self::class)]
#[JoinColumn(deferrable: true)]
#[JoinColumn(deferrable: true, deferred: true)]
private self $parent;
}
2 changes: 2 additions & 0 deletions tests/Tests/ORM/Mapping/JoinColumnMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function testItSurvivesSerialization(): void
$mapping = new JoinColumnMapping('foo', 'id');

$mapping->deferrable = true;
$mapping->deferred = true;
$mapping->unique = true;
$mapping->quoted = true;
$mapping->fieldName = 'bar';
Expand All @@ -31,6 +32,7 @@ public function testItSurvivesSerialization(): void
assert($resurrectedMapping instanceof JoinColumnMapping);

self::assertTrue($resurrectedMapping->deferrable);
self::assertTrue($resurrectedMapping->deferred);
self::assertSame('foo', $resurrectedMapping->name);
self::assertTrue($resurrectedMapping->unique);
self::assertTrue($resurrectedMapping->quoted);
Expand Down