Skip to content

Commit

Permalink
Merge pull request #1121 from deeky666/DDC-3274
Browse files Browse the repository at this point in the history
[DDC-3274] Improve schema validator error message for invalid bi-directional relations
  • Loading branch information
Ocramius committed Aug 26, 2014
2 parents 65f8357 + 8d3fba5 commit 91fa4c9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/SchemaValidator.php
Expand Up @@ -124,7 +124,7 @@ public function validateClass(ClassMetadataInfo $class)
$ce[] = "The field " . $class->name . "#" . $fieldName . " is on the inverse 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=".$fieldName."' attribute.";
"'inversedBy=\"" . $fieldName . "\"' attribute.";
} elseif ($targetMetadata->associationMappings[$assoc['mappedBy']]['inversedBy'] != $fieldName) {
$ce[] = "The mappings " . $class->name . "#" . $fieldName . " and " .
$assoc['targetEntity'] . "#" . $assoc['mappedBy'] . " are ".
Expand Down
45 changes: 45 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php
Expand Up @@ -134,6 +134,24 @@ public function testInvalidTripleAssociationAsKeyMapping()
"The referenced column name 'id' has to be a primary key column on the target entity class 'Doctrine\Tests\ORM\Tools\DDC1649Two'."
), $ce);
}

/**
* @group DDC-3274
*/
public function testInvalidBiDirectionalRelationMappingMissingInversedByAttribute()
{
$class = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC3274One');
$ce = $this->validator->validateClass($class);

$this->assertEquals(
array(
"The field Doctrine\Tests\ORM\Tools\DDC3274One#two is on the inverse side of a bi-directional " .
"relationship, but the specified mappedBy association on the target-entity " .
"Doctrine\Tests\ORM\Tools\DDC3274Two#one does not contain the required 'inversedBy=\"two\"' attribute."
),
$ce
);
}
}

/**
Expand Down Expand Up @@ -263,3 +281,30 @@ class DDC1649Three
private $two;
}

/**
* @Entity
*/
class DDC3274One
{
/**
* @Id @Column @GeneratedValue
*/
private $id;

/**
* @OneToMany(targetEntity="DDC3274Two", mappedBy="one")
*/
private $two;
}

/**
* @Entity
*/
class DDC3274Two
{
/**
* @Id
* @ManyToOne(targetEntity="DDC3274One")
*/
private $one;
}

0 comments on commit 91fa4c9

Please sign in to comment.