1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Tools\SchemaTool; |
6
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
7
|
|
|
|
8
|
|
|
class OneToOneInverseSideLoadAfterDqlQueryTest extends OrmFunctionalTestCase |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
View Code Duplication |
protected function setUp() |
12
|
|
|
{ |
13
|
|
|
parent::setUp(); |
14
|
|
|
$schemaTool = new SchemaTool($this->_em); |
15
|
|
|
try { |
16
|
|
|
$schemaTool->createSchema( |
17
|
|
|
[ |
18
|
|
|
$this->_em->getClassMetadata(Bus::class), |
19
|
|
|
$this->_em->getClassMetadata(BusOwner::class), |
20
|
|
|
] |
21
|
|
|
); |
22
|
|
|
} catch(\Exception $e) {} |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testInverseSideOneToOneLoadedAfterDqlQuery(): void |
26
|
|
|
{ |
27
|
|
|
$owner = new BusOwner('Alexander'); |
28
|
|
|
$bus = new Bus($owner); |
29
|
|
|
|
30
|
|
|
$this->_em->persist($bus); |
31
|
|
|
$this->_em->flush(); |
32
|
|
|
$this->_em->clear(); |
33
|
|
|
|
34
|
|
|
$bus = $this->_em->createQueryBuilder() |
|
|
|
|
35
|
|
|
->select('to') |
36
|
|
|
->from(BusOwner::class, 'to') |
37
|
|
|
->andWhere('to.id = :id') |
38
|
|
|
->setParameter('id', $owner->id) |
39
|
|
|
->getQuery() |
40
|
|
|
->getResult(); |
41
|
|
|
|
42
|
|
|
$this->assertSQLEquals( |
43
|
|
|
"SELECT b0_.id AS id_0, b0_.name AS name_1 FROM BusOwner b0_ WHERE b0_.id = ?", |
44
|
|
|
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql'] |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$this->assertSQLEquals( |
48
|
|
|
"SELECT t0.id AS id_1, t0.owner AS owner_2 FROM Bus t0 WHERE t0.owner = ?", |
49
|
|
|
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Entity |
58
|
|
|
*/ |
59
|
|
|
class Bus |
60
|
|
|
{ |
61
|
|
|
/** |
62
|
|
|
* @id @column(type="integer") @generatedValue |
63
|
|
|
* @var int |
64
|
|
|
*/ |
65
|
|
|
public $id; |
66
|
|
|
/** |
67
|
|
|
* Owning side |
68
|
|
|
* @OneToOne(targetEntity="BusOwner", inversedBy="bus", cascade={"persist"}) |
69
|
|
|
* @JoinColumn(nullable=false, name="owner") |
70
|
|
|
*/ |
71
|
|
|
public $owner; |
72
|
|
|
|
73
|
|
|
public function __construct(BusOwner $owner) |
74
|
|
|
{ |
75
|
|
|
$this->owner = $owner; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @Entity |
82
|
|
|
*/ |
83
|
|
|
class BusOwner |
84
|
|
|
{ |
85
|
|
|
/** |
86
|
|
|
* @Id |
87
|
|
|
* @Column(type="integer") |
88
|
|
|
* @GeneratedValue |
89
|
|
|
*/ |
90
|
|
|
public $id; |
91
|
|
|
|
92
|
|
|
/** @column(type="string") */ |
93
|
|
|
public $name; |
94
|
|
|
/** |
95
|
|
|
* Inverse side |
96
|
|
|
* @OneToOne(targetEntity="Bus", mappedBy="owner") |
97
|
|
|
*/ |
98
|
|
|
public $bus; |
99
|
|
|
|
100
|
|
|
public function __construct($name) |
101
|
|
|
{ |
102
|
|
|
$this->name = $name; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setBus(Bus $t) |
106
|
|
|
{ |
107
|
|
|
$this->bus = $t; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|