forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework association mapping hierarchy
- Each type is now either final, abstract or an interface. - The mappedBy attribute is no longer nullable and moved down the hierarchy. - The inversedBy attribute is still nullable and also moved down the hierarchy. - Code common to ManyToOneAssociationMapping and OneToOneOwningSideMapping is de-duplicated and moved up the hierarchy - Code inside ToManyInverseSideMapping and ToManyOwningSideMapping comes from a trait to avoid duplication.
- Loading branch information
Showing
35 changed files
with
507 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Mapping; | ||
|
||
abstract class InverseSideMapping extends AssociationMapping | ||
{ | ||
/** | ||
* required for bidirectional associations | ||
* The name of the field that completes the bidirectional association on | ||
* the owning side. This key must be specified on the inverse side of a | ||
* bidirectional association. | ||
*/ | ||
public string $mappedBy; | ||
|
||
final public function backRefFieldName(): string | ||
{ | ||
return $this->mappedBy; | ||
} | ||
|
||
/** @return list<string> */ | ||
public function __sleep(): array | ||
{ | ||
return [ | ||
...parent::__sleep(), | ||
'mappedBy', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Mapping; | ||
|
||
final class ManyToManyInverseSideMapping extends ToManyInverseSideMapping implements ManyToManyAssociationMapping | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Mapping; | ||
|
||
final class OneToOneInverseSideMapping extends ToOneInverseSideMapping implements OneToOneAssociationMapping | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Mapping; | ||
|
||
abstract class OwningSideMapping extends AssociationMapping | ||
{ | ||
/** | ||
* required for bidirectional associations | ||
* The name of the field that completes the bidirectional association on | ||
* the inverse side. This key must be specified on the owning side of a | ||
* bidirectional association. | ||
*/ | ||
public string|null $inversedBy = null; | ||
|
||
/** @return list<string> */ | ||
public function __sleep(): array | ||
{ | ||
$serialized = parent::__sleep(); | ||
|
||
if ($this->inversedBy !== null) { | ||
$serialized[] = 'inversedBy'; | ||
} | ||
|
||
return $serialized; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
lib/Doctrine/ORM/Mapping/ToManyAssociationMappingImplementation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Mapping; | ||
|
||
/** @internal */ | ||
trait ToManyAssociationMappingImplementation | ||
{ | ||
/** | ||
* Specification of a field on target-entity that is used to index the | ||
* collection by. This field HAS to be either the primary key or a unique | ||
* column. Otherwise the collection does not contain all the entities that | ||
* are actually related. | ||
*/ | ||
public string|null $indexBy = null; | ||
|
||
/** | ||
* A map of field names (of the target entity) to sorting directions | ||
* | ||
* @var array<string, 'asc'|'desc'>|null | ||
*/ | ||
public array|null $orderBy = null; | ||
|
||
/** @return list<string> */ | ||
public function __sleep(): array | ||
{ | ||
$serialized = parent::__sleep(); | ||
|
||
foreach (['indexBy', 'orderBy'] as $stringOrArrayKey) { | ||
if ($this->$stringOrArrayKey !== null) { | ||
$serialized[] = $stringOrArrayKey; | ||
} | ||
} | ||
|
||
return $serialized; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Mapping; | ||
|
||
abstract class ToManyInverseSideMapping extends InverseSideMapping implements ToManyAssociationMapping | ||
{ | ||
use ToManyAssociationMappingImplementation; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Mapping; | ||
|
||
abstract class ToManyOwningSideMapping extends OwningSideMapping | ||
{ | ||
use ToManyAssociationMappingImplementation; | ||
} |
Oops, something went wrong.