Skip to content
Merged
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
15 changes: 10 additions & 5 deletions lib/Doctrine/ORM/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use function array_diff;
use function array_intersect;
use function array_key_exists;
use function array_keys;
use function array_map;
use function array_merge;
Expand Down Expand Up @@ -1259,12 +1260,16 @@ protected function validateAndCompleteFieldMapping(array $mapping): FieldMapping
*/
protected function _validateAndCompleteAssociationMapping(array $mapping): AssociationMapping
{
if (! isset($mapping['mappedBy'])) {
$mapping['mappedBy'] = null;
if (array_key_exists('mappedBy', $mapping) && $mapping['mappedBy'] === null) {
unset($mapping['mappedBy']);
}

if (array_key_exists('inversedBy', $mapping) && $mapping['inversedBy'] === null) {
unset($mapping['inversedBy']);
}

if (! isset($mapping['inversedBy'])) {
$mapping['inversedBy'] = null;
if (array_key_exists('joinColumns', $mapping) && in_array($mapping['joinColumns'], [null, []], true)) {
unset($mapping['joinColumns']);
}

$mapping['isOwningSide'] = true; // assume owning side until we hit mappedBy
Expand Down Expand Up @@ -1334,7 +1339,7 @@ protected function _validateAndCompleteAssociationMapping(array $mapping): Assoc
}

// Mandatory and optional attributes for either side
if (! $mapping['mappedBy']) {
if (! isset($mapping['mappedBy'])) {
if (isset($mapping['joinTable'])) {
if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] === '`') {
$mapping['joinTable']['name'] = trim($mapping['joinTable']['name'], '`');
Expand Down
9 changes: 0 additions & 9 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ public function testCreateManyToOne(): void
],
],
'type' => 2,
'mappedBy' => null,
'inversedBy' => null,
'isOwningSide' => true,
'sourceEntity' => CmsUser::class,
Expand Down Expand Up @@ -380,7 +379,6 @@ public function testCreateManyToOneWithIdentity(): void
],
],
'type' => 2,
'mappedBy' => null,
'inversedBy' => null,
'isOwningSide' => true,
'sourceEntity' => CmsUser::class,
Expand Down Expand Up @@ -433,7 +431,6 @@ public function testCreateOneToOne(): void
],
],
'type' => 1,
'mappedBy' => null,
'inversedBy' => null,
'isOwningSide' => true,
'sourceEntity' => CmsUser::class,
Expand Down Expand Up @@ -489,7 +486,6 @@ public function testCreateOneToOneWithIdentity(): void
],
],
'type' => 1,
'mappedBy' => null,
'inversedBy' => null,
'isOwningSide' => true,
'sourceEntity' => CmsUser::class,
Expand Down Expand Up @@ -575,7 +571,6 @@ public function testCreateManyToMany(): void
'name' => 'groups_users',
],
'type' => 8,
'mappedBy' => null,
'inversedBy' => null,
'isOwningSide' => true,
'isOnDeleteCascade' => true,
Expand Down Expand Up @@ -630,7 +625,6 @@ public function testCreateOneToMany(): void
'orderBy' => [0 => 'test'],
'indexBy' => 'test',
'type' => 4,
'inversedBy' => null,
'isOwningSide' => false,
'sourceEntity' => CmsUser::class,
'fetch' => 2,
Expand Down Expand Up @@ -683,7 +677,6 @@ public function testOrphanRemovalOnCreateOneToOne(): void
],
],
'type' => 1,
'mappedBy' => null,
'inversedBy' => null,
'isOwningSide' => true,
'sourceEntity' => CmsUser::class,
Expand Down Expand Up @@ -718,7 +711,6 @@ public function testOrphanRemovalOnCreateOneToMany(): void
'targetEntity' => CmsGroup::class,
'mappedBy' => 'test',
'type' => 4,
'inversedBy' => null,
'isOwningSide' => false,
'sourceEntity' => CmsUser::class,
'fetch' => 2,
Expand Down Expand Up @@ -777,7 +769,6 @@ public function testOrphanRemovalOnManyToMany(): void
'name' => 'cmsuser_cmsgroup',
],
'type' => 8,
'mappedBy' => null,
'inversedBy' => null,
'isOwningSide' => true,
'sourceEntity' => CmsUser::class,
Expand Down