diff --git a/src/Mapping/ClassMetadata.php b/src/Mapping/ClassMetadata.php index 7c9020805a5..da056dcb12a 100644 --- a/src/Mapping/ClassMetadata.php +++ b/src/Mapping/ClassMetadata.php @@ -1687,7 +1687,7 @@ public function setInheritanceType(int $type): void /** * Sets the association to override association mapping of property for an entity relationship. * - * @psalm-param array $overrideMapping + * @psalm-param array{joinColumns?: array, inversedBy?: ?string, joinTable?: array, fetch?: ?string, cascade?: string[]} $overrideMapping * * @throws MappingException */ @@ -1723,6 +1723,10 @@ public function setAssociationOverride(string $fieldName, array $overrideMapping $mapping['fetch'] = $overrideMapping['fetch']; } + if (isset($overrideMapping['cascade'])) { + $mapping['cascade'] = $overrideMapping['cascade']; + } + switch ($mapping['type']) { case self::ONE_TO_ONE: case self::MANY_TO_ONE: diff --git a/tests/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Tests/ORM/Mapping/ClassMetadataTest.php index 38b2bde7ca9..f187371dfd0 100644 --- a/tests/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Tests/ORM/Mapping/ClassMetadataTest.php @@ -872,13 +872,23 @@ public function testAssociationOverrideKeepsDeclaringClass(): void { $cm = new ClassMetadata(Directory::class); $cm->mapManyToOne(['fieldName' => 'parentDirectory', 'targetEntity' => Directory::class, 'cascade' => ['remove'], 'declared' => Directory::class]); - $cm->setAssociationOverride('parentDirectory', ['cascade' => '']); + $cm->setAssociationOverride('parentDirectory', ['cascade' => ['remove']]); $mapping = $cm->getAssociationMapping('parentDirectory'); self::assertSame(Directory::class, $mapping->declared); } + public function testAssociationOverrideCanOverrideCascade(): void + { + $cm = new ClassMetadata(Directory::class); + $cm->mapManyToOne(['fieldName' => 'parentDirectory', 'targetEntity' => Directory::class, 'cascade' => ['remove'], 'declared' => Directory::class]); + $cm->setAssociationOverride('parentDirectory', ['cascade' => ['all']]); + + $mapping = $cm->getAssociationMapping('parentDirectory'); + self::assertSame(['remove', 'persist', 'refresh', 'detach'], $mapping['cascade']); + } + #[TestGroup('DDC-1955')] public function testInvalidEntityListenerClassException(): void {