Skip to content

Commit 80eb85b

Browse files
mpdudebobdercole
andcommitted
Add regression test for a to-many relationship on a base class & mapped superclass in the hierarchy
This picks the test case from doctrine#9517 and rebases it onto 2.14.x. The problem has been covered in doctrine#8415, so this PR closes doctrine#9517 and fixes doctrine#9516. Co-authored-by: Robert D'Ercole <bobdercole@gmail.com>
1 parent ed56f42 commit 80eb85b

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional\Ticket;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
use Doctrine\ORM\Mapping\Column;
9+
use Doctrine\ORM\Mapping\Entity;
10+
use Doctrine\ORM\Mapping\Id;
11+
use Doctrine\ORM\Mapping\ManyToOne;
12+
use Doctrine\ORM\Mapping\MappedSuperclass;
13+
use Doctrine\ORM\Mapping\OneToMany;
14+
use Doctrine\Tests\OrmFunctionalTestCase;
15+
16+
class GH9516Test extends OrmFunctionalTestCase
17+
{
18+
public function testEntityCanHaveInverseOneToManyAssociationWithChildMappedSuperclass(): void
19+
{
20+
$sportsCarMetadata = $this->_em->getClassMetadata(GH9516SportsCar::class);
21+
$this->assertTrue($sportsCarMetadata->hasAssociation('passengers'));
22+
}
23+
}
24+
25+
/** @Entity */
26+
class GH9516Passenger
27+
{
28+
/**
29+
* @Id
30+
* @Column(type="integer")
31+
* @var int $id
32+
*/
33+
private $id;
34+
35+
/**
36+
* @ManyToOne(targetEntity="GH9516Vehicle", inversedBy="passengers")
37+
* @var GH9516Vehicle $vehicle
38+
*/
39+
private $vehicle;
40+
}
41+
42+
/**
43+
* @ORM\DiscriminatorColumn(name="type", type="string")
44+
* @ORM\DiscriminatorMap({ "sports" = "\Doctrine\Tests\ORM\Functional\Ticket\GH9516SportsCar" })
45+
* @ORM\InheritanceType("SINGLE_TABLE")
46+
*
47+
* @Entity
48+
*/
49+
abstract class GH9516Vehicle
50+
{
51+
/**
52+
* @Id
53+
* @Column(type="integer")
54+
* @var int $id
55+
*/
56+
private $id;
57+
58+
/**
59+
* @OneToMany(targetEntity="GH9516Passenger", mappedBy="vehicle")
60+
* @var GH9516Passenger[] $passengers
61+
*/
62+
private $passengers;
63+
}
64+
65+
/**
66+
* @MappedSuperclass
67+
*/
68+
abstract class GH9516Car extends GH9516Vehicle
69+
{
70+
}
71+
72+
/**
73+
* @Entity
74+
*/
75+
class GH9516SportsCar extends GH9516Car
76+
{
77+
}

0 commit comments

Comments
 (0)