1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
6
|
|
|
use Doctrine\ORM\Query; |
7
|
|
|
use Doctrine\ORM\Query\ResultSetMapping; |
8
|
|
|
use Doctrine\Tests\Mocks\HydratorMockStatement; |
9
|
|
|
|
10
|
|
|
final class GH6362Test extends OrmFunctionalTestCase |
11
|
|
|
{ |
12
|
|
|
protected function setUp() |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
|
16
|
|
|
$this->_schemaTool->createSchema( |
17
|
|
|
[ |
18
|
|
|
$this->_em->getClassMetadata(GH6362Start::class), |
19
|
|
|
$this->_em->getClassMetadata(GH6362Base::class), |
20
|
|
|
$this->_em->getClassMetadata(GH6362Child::class), |
21
|
|
|
$this->_em->getClassMetadata(GH6362Join::class), |
22
|
|
|
] |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @group 6362 |
28
|
|
|
* |
29
|
|
|
* SELECT a as base, b, c, d |
30
|
|
|
* FROM Start a |
31
|
|
|
* LEFT JOIN a.bases b |
32
|
|
|
* LEFT JOIN Child c WITH b.id = c.id |
33
|
|
|
* LEFT JOIN c.joins d |
34
|
|
|
*/ |
35
|
|
|
public function testInheritanceJoinAlias() |
36
|
|
|
{ |
37
|
|
|
$rsm = new ResultSetMapping; |
38
|
|
|
$rsm->addEntityResult(GH6362Start::class, 'a', 'base'); |
39
|
|
|
$rsm->addJoinedEntityResult(GH6362Base::class, 'b', 'a', 'bases'); |
40
|
|
|
$rsm->addEntityResult(GH6362Child::class, 'c'); |
41
|
|
|
$rsm->addJoinedEntityResult(GH6362Join::class, 'd', 'c', 'joins'); |
42
|
|
|
|
43
|
|
|
$rsm->addFieldResult('a', 'id_0', 'id'); |
44
|
|
|
$rsm->addFieldResult('b', 'id_1', 'id'); |
45
|
|
|
$rsm->addFieldResult('c', 'id_2', 'id'); |
46
|
|
|
$rsm->addFieldResult('d', 'id_3', 'id'); |
47
|
|
|
|
48
|
|
|
$rsm->addMetaResult('a', 'bases_id_4', 'bases_id', false, 'integer'); |
49
|
|
|
$rsm->addMetaResult('b', 'type_5', 'type'); |
50
|
|
|
$rsm->addMetaResult('c', 'type_6', 'type'); |
51
|
|
|
$rsm->addMetaResult('d', 'child_id_7', 'child_id', false, 'integer'); |
52
|
|
|
|
53
|
|
|
$rsm->setDiscriminatorColumn('b', 'type_5'); |
54
|
|
|
$rsm->setDiscriminatorColumn('c', 'type_6'); |
55
|
|
|
|
56
|
|
|
$resultSet = [ |
57
|
|
|
[ |
58
|
|
|
'id_0' => '1', |
59
|
|
|
'id_1' => '1', |
60
|
|
|
'id_2' => '1', |
61
|
|
|
'id_3' => '1', |
62
|
|
|
'bases_id_4' => '1', |
63
|
|
|
'type_5' => 'child', |
64
|
|
|
'type_6' => 'child', |
65
|
|
|
'child_id_7' => '1', |
66
|
|
|
], |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
$stmt = new HydratorMockStatement($resultSet); |
70
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); |
71
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); |
72
|
|
|
|
73
|
|
|
$this->assertInstanceOf(GH6362Start::class, $result[0]['base']); |
74
|
|
|
$this->assertInstanceOf(GH6362Child::class, $result[1][0]); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @Entity |
80
|
|
|
*/ |
81
|
|
|
class GH6362Start |
82
|
|
|
{ |
83
|
|
|
/** |
84
|
|
|
* @Column(type="integer") |
85
|
|
|
* @Id |
86
|
|
|
* @GeneratedValue |
87
|
|
|
*/ |
88
|
|
|
protected $id; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @ManyToOne(targetEntity="GH6362Base", inversedBy="starts") |
92
|
|
|
*/ |
93
|
|
|
private $bases; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @InheritanceType("SINGLE_TABLE") |
98
|
|
|
* @DiscriminatorColumn(name="type", type="string") |
99
|
|
|
* @DiscriminatorMap({"child" = "GH6362Child"}) |
100
|
|
|
* @Entity |
101
|
|
|
*/ |
102
|
|
|
abstract class GH6362Base |
103
|
|
|
{ |
104
|
|
|
/** |
105
|
|
|
* @Column(type="integer") |
106
|
|
|
* @Id |
107
|
|
|
* @GeneratedValue |
108
|
|
|
*/ |
109
|
|
|
protected $id; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @OneToMany(targetEntity="GH6362Start", mappedBy="bases") |
113
|
|
|
*/ |
114
|
|
|
private $starts; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @Entity |
119
|
|
|
*/ |
120
|
|
|
class GH6362Child extends GH6362Base |
121
|
|
|
{ |
122
|
|
|
/** |
123
|
|
|
* @OneToMany(targetEntity="GH6362Join", mappedBy="child") |
124
|
|
|
*/ |
125
|
|
|
private $joins; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @Entity |
130
|
|
|
*/ |
131
|
|
|
class GH6362Join |
132
|
|
|
{ |
133
|
|
|
/** |
134
|
|
|
* @Column(type="integer") |
135
|
|
|
* @Id |
136
|
|
|
* @GeneratedValue |
137
|
|
|
*/ |
138
|
|
|
private $id; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @ManyToOne(targetEntity="GH6362Child", inversedBy="joins") |
142
|
|
|
*/ |
143
|
|
|
private $child; |
144
|
|
|
} |
145
|
|
|
|