Skip to content

Commit f3764fc

Browse files
committed
orphanRemoval belongs in the base relation object
1 parent 07a4383 commit f3764fc

File tree

7 files changed

+15
-33
lines changed

7 files changed

+15
-33
lines changed

src/Doctrine/BaseCollectionRelation.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
abstract class BaseCollectionRelation extends BaseRelation
2020
{
21-
abstract public function getOrphanRemoval(): bool;
22-
2321
abstract public function getTargetSetterMethodName(): string;
2422

2523
public function getAdderMethodName(): string

src/Doctrine/BaseRelation.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public function __construct(
2525
private bool $avoidSetter = false,
2626
private bool $isCustomReturnTypeNullable = false,
2727
private ?string $customReturnType = null,
28-
protected bool $isOwning = false,
28+
private bool $isOwning = false,
29+
private bool $orphanRemoval = false,
2930
) {
3031
// @TODO - triggers are tmp, do not merge w/ them in place.
3132
if (null === $this->targetPropertyName) {
@@ -77,4 +78,9 @@ public function isOwning(): bool
7778
{
7879
return $this->isOwning;
7980
}
81+
82+
public function getOrphanRemoval(): bool
83+
{
84+
return $this->orphanRemoval;
85+
}
8086
}

src/Doctrine/EntityRegenerator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ public function regenerateEntities(string $classOrNamespace): void
140140
propertyName: $mapping['fieldName'],
141141
targetClassName: $mapping['targetEntity'],
142142
targetPropertyName: $mapping['mappedBy'],
143-
))
144-
->setOrphanRemoval($mapping['orphanRemoval'])
145-
;
143+
orphanRemoval: $mapping['orphanRemoval'],
144+
));
146145

147146
$manipulator->addOneToManyRelation($relation);
148147

src/Doctrine/EntityRelation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public function getInverseRelation(): RelationManyToMany|RelationOneToOne|Relati
119119
targetClassName: $this->owningClass,
120120
targetPropertyName: $this->owningProperty,
121121
isSelfReferencing: $this->isSelfReferencing,
122-
))
123-
->setOrphanRemoval($this->orphanRemoval),
122+
orphanRemoval: $this->orphanRemoval,
123+
)),
124124
self::MANY_TO_MANY => (new RelationManyToMany(
125125
propertyName: $this->inverseProperty,
126126
targetClassName: $this->owningClass,

src/Doctrine/RelationManyToMany.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
*/
1919
final class RelationManyToMany extends BaseCollectionRelation
2020
{
21-
public function getOrphanRemoval(): bool
22-
{
23-
return false;
24-
}
25-
2621
public function getTargetSetterMethodName(): string
2722
{
2823
return 'add'.Str::asCamelCase(Str::pluralCamelCaseToSingular($this->getTargetPropertyName()));

src/Doctrine/RelationOneToMany.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@
1818
*/
1919
final class RelationOneToMany extends BaseCollectionRelation
2020
{
21-
private $orphanRemoval;
22-
23-
public function getOrphanRemoval(): bool
24-
{
25-
return $this->orphanRemoval;
26-
}
27-
28-
public function setOrphanRemoval($orphanRemoval): self
29-
{
30-
$this->orphanRemoval = $orphanRemoval;
31-
32-
return $this;
33-
}
34-
3521
public function getTargetGetterMethodName(): string
3622
{
3723
return 'get'.Str::asCamelCase($this->getTargetPropertyName());

tests/Util/ClassSourceManipulatorTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,7 @@ public function getAddOneToManyRelationTests(): \Generator
492492
propertyName: 'avatarPhotos',
493493
targetClassName: \App\Entity\UserAvatarPhoto::class,
494494
targetPropertyName: 'user',
495-
))
496-
->setOrphanRemoval(false),
495+
)),
497496
];
498497

499498
// interesting also because the source file has its
@@ -505,8 +504,7 @@ public function getAddOneToManyRelationTests(): \Generator
505504
propertyName: 'avatarPhotos',
506505
targetClassName: \App\Entity\UserAvatarPhoto::class,
507506
targetPropertyName: 'user',
508-
))
509-
->setOrphanRemoval(false),
507+
)),
510508
];
511509

512510
yield 'one_to_many_orphan_removal' => [
@@ -516,8 +514,8 @@ public function getAddOneToManyRelationTests(): \Generator
516514
propertyName: 'avatarPhotos',
517515
targetClassName: \App\Entity\UserAvatarPhoto::class,
518516
targetPropertyName: 'user',
519-
))
520-
->setOrphanRemoval(true),
517+
orphanRemoval: true,
518+
)),
521519
];
522520

523521
// todo test existing constructor

0 commit comments

Comments
 (0)