Skip to content

Commit

Permalink
Merge branch '2.11.x' into 2.12.x
Browse files Browse the repository at this point in the history
* 2.11.x:
  Fix bug-#9536
  • Loading branch information
derrabus committed Feb 24, 2022
2 parents ec7c637 + 856c314 commit 021444b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ public function validateClass(ClassMetadataInfo $class)
'field ' . $assoc['targetEntity'] . '#' . $assoc['inversedBy'] . ' which does not exist.';
} elseif ($targetMetadata->associationMappings[$assoc['inversedBy']]['mappedBy'] === null) {
$ce[] = 'The field ' . $class->name . '#' . $fieldName . ' is on the owning side of a ' .
'bi-directional relationship, but the specified mappedBy association on the target-entity ' .
$assoc['targetEntity'] . '#' . $assoc['mappedBy'] . ' does not contain the required ' .
"'inversedBy' attribute.";
'bi-directional relationship, but the specified inversedBy association on the target-entity ' .
$assoc['targetEntity'] . '#' . $assoc['inversedBy'] . ' does not contain the required ' .
"'mappedBy=\"" . $fieldName . "\"' attribute.";
} elseif ($targetMetadata->associationMappings[$assoc['inversedBy']]['mappedBy'] !== $fieldName) {
$ce[] = 'The mappings ' . $class->name . '#' . $fieldName . ' and ' .
$assoc['targetEntity'] . '#' . $assoc['inversedBy'] . ' are ' .
Expand Down
59 changes: 59 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@ public function testInvalidBiDirectionalRelationMappingMissingInversedByAttribut
);
}

/**
* @group 9536
*/
public function testInvalidBiDirectionalRelationMappingMissingMappedByAttribute(): void
{
$class = $this->em->getClassMetadata(Issue9536Owner::class);
$ce = $this->validator->validateClass($class);

self::assertEquals(
[
'The field Doctrine\Tests\ORM\Tools\Issue9536Owner#one is on the owning side of a bi-directional ' .
'relationship, but the specified inversedBy association on the target-entity ' .
"Doctrine\Tests\ORM\Tools\Issue9536Target#two does not contain the required 'mappedBy=\"one\"' " .
'attribute.',
],
$ce
);
}

/**
* @group DDC-3322
*/
Expand Down Expand Up @@ -435,6 +454,46 @@ class DDC3274Two
private $one;
}

/**
* @Entity
*/
class Issue9536Target
{
/**
* @var mixed
* @Id
* @Column
* @GeneratedValue
*/
private $id;

/**
* @var Issue9536Owner
* @OneToOne(targetEntity="Issue9536Owner")
*/
private $two;
}

/**
* @Entity
*/
class Issue9536Owner
{
/**
* @var mixed
* @Id
* @Column
* @GeneratedValue
*/
private $id;

/**
* @var Issue9536Target
* @OneToOne(targetEntity="Issue9536Target", inversedBy="two")
*/
private $one;
}

/**
* @Entity
*/
Expand Down

0 comments on commit 021444b

Please sign in to comment.