Skip to content

Commit

Permalink
[GH-8031] Verify assocations still do not work with Embeddables.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Mar 2, 2020
1 parent a8cd2d4 commit 27575b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,9 @@ protected function getDriver()
*/
protected function isEntity(ClassMetadataInterface $class)
{
return isset($class->isMappedSuperclass) && $class->isMappedSuperclass === false
&& isset($class->isEmbeddedClass) && $class->isEmbeddedClass === false;
assert($class instanceof ClassMetadata);

return $class->isMappedSuperclass === false && $class->isEmbeddedClass === false;
}

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH8031Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ public function testEntityIsFetched()
$this->_em->getRepository(GH8031Invoice::class)->findBy([], ['code.number' => 'ASC'])
);
}

public function testEmbeddableWithAssociationNotAllowed()
{
$cm = $this->_em->getClassMetadata(GH8031EmbeddableWithAssociation::class);

$this->assertArrayHasKey('invoice', $cm->associationMappings);

$cm = $this->_em->getClassMetadata(GH8031Invoice::class);

$this->assertCount(0, $cm->associationMappings);
}
}

/**
* @Embeddable
*/
class GH8031EmbeddableWithAssociation
{
/**
* @ManyToOne(targetEntity=GH8031Invoice::class)
*/
public $invoice;
}

/**
Expand Down Expand Up @@ -123,6 +145,11 @@ class GH8031Invoice
*/
private $code;

/**
* @Embedded(class=GH8031EmbeddableWithAssociation::class)
*/
private $embeddedAssoc;

public function __construct(GH8031InvoiceCode $code)
{
$this->code = $code;
Expand Down

0 comments on commit 27575b8

Please sign in to comment.