[DDC-1649] Add additional check for not allowed mapping of dependent association keys.
This commit is contained in:
parent
af07bd7818
commit
502585bf40
@ -106,6 +106,11 @@ class SchemaValidator
|
|||||||
|
|
||||||
$targetMetadata = $cmf->getMetadataFor($assoc['targetEntity']);
|
$targetMetadata = $cmf->getMetadataFor($assoc['targetEntity']);
|
||||||
|
|
||||||
|
if ($assoc['id'] && $targetMetadata->containsForeignIdentifier) {
|
||||||
|
$ce[] = "Cannot map association '" . $class->name. "#". $fieldName ." as identifier, because " .
|
||||||
|
"the target entity '". $targetMetadata->name . "' also maps an association as identifier.";
|
||||||
|
}
|
||||||
|
|
||||||
/* @var $assoc AssociationMapping */
|
/* @var $assoc AssociationMapping */
|
||||||
if ($assoc['mappedBy']) {
|
if ($assoc['mappedBy']) {
|
||||||
if ($targetMetadata->hasField($assoc['mappedBy'])) {
|
if ($targetMetadata->hasField($assoc['mappedBy'])) {
|
||||||
|
@ -122,6 +122,20 @@ class SchemaValidatorTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
|
|
||||||
$this->assertEquals(array(), $ce);
|
$this->assertEquals(array(), $ce);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1649
|
||||||
|
*/
|
||||||
|
public function testInvalidTripleAssociationAsKeyMapping()
|
||||||
|
{
|
||||||
|
$classThree = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC1649Three');
|
||||||
|
$ce = $this->validator->validateClass($classThree);
|
||||||
|
|
||||||
|
$this->assertEquals(Array(
|
||||||
|
"Cannot map association 'Doctrine\Tests\ORM\Tools\DDC1649Three#two as identifier, because the target entity 'Doctrine\Tests\ORM\Tools\DDC1649Two' also maps an association as identifier.",
|
||||||
|
"The referenced column name 'id' has to be a primary key column on the target entity class 'Doctrine\Tests\ORM\Tools\DDC1649Two'."
|
||||||
|
), $ce);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,3 +235,33 @@ class DDC1587ValidEntity2
|
|||||||
private $num;
|
private $num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC1649One
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id @Column @GeneratedValue
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC1649Two
|
||||||
|
{
|
||||||
|
/** @Id @ManyToOne(targetEntity="DDC1649One")@JoinColumn(name="id", referencedColumnName="id") */
|
||||||
|
public $one;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC1649Three
|
||||||
|
{
|
||||||
|
/** @Id @ManyToOne(targetEntity="DDC1649Two") @JoinColumn(name="id",
|
||||||
|
* referencedColumnName="id") */
|
||||||
|
private $two;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user