-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ne-inverse-not-being-loaded-with-correct-identifier-restrictions #6759 showstopper one-to-one inverse not being loaded with correct identifier restrictions when defining `joinColumn`
- Loading branch information
Showing
4 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/Doctrine/Tests/Models/OneToOneInverseSideLoad/InverseSide.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\OneToOneInverseSideLoad; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @Entity() | ||
* @Table(name="one_to_one_inverse_side_load_inverse") | ||
*/ | ||
class InverseSide | ||
{ | ||
/** | ||
* @Id() | ||
* @Column(type="string") | ||
* @GeneratedValue(strategy="NONE") | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @OneToOne(targetEntity=OwningSide::class, mappedBy="inverse") | ||
*/ | ||
public $owning; | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Doctrine/Tests/Models/OneToOneInverseSideLoad/OwningSide.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\OneToOneInverseSideLoad; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @Entity() | ||
* @Table(name="one_to_one_inverse_side_load_owning") | ||
*/ | ||
class OwningSide | ||
{ | ||
/** | ||
* @Id() | ||
* @Column(type="string") | ||
* @GeneratedValue(strategy="NONE") | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* Owning side | ||
* | ||
* @OneToOne(targetEntity=InverseSide::class, inversedBy="owning") | ||
* @JoinColumn(nullable=false, name="inverse") | ||
*/ | ||
public $inverse; | ||
} |
70 changes: 70 additions & 0 deletions
70
tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\ORM\Tools\ToolsException; | ||
use Doctrine\Tests\Models\OneToOneInverseSideLoad\InverseSide; | ||
use Doctrine\Tests\Models\OneToOneInverseSideLoad\OwningSide; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
class OneToOneInverseSideLoadAfterDqlQueryTest extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
try { | ||
$this->_schemaTool->createSchema([ | ||
$this->_em->getClassMetadata(OwningSide::class), | ||
$this->_em->getClassMetadata(InverseSide::class), | ||
]); | ||
} catch(ToolsException $e) { | ||
// ignored | ||
} | ||
} | ||
|
||
/** | ||
* @group 6759 | ||
*/ | ||
public function testInverseSideOneToOneLoadedAfterDqlQuery(): void | ||
{ | ||
$owner = new OwningSide(); | ||
$inverse = new InverseSide(); | ||
|
||
$owner->id = 'owner'; | ||
$inverse->id = 'inverse'; | ||
$owner->inverse = $inverse; | ||
$inverse->owning = $owner; | ||
|
||
$this->_em->persist($owner); | ||
$this->_em->persist($inverse); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
/* @var $fetchedInverse InverseSide */ | ||
$fetchedInverse = $this | ||
->_em | ||
->createQueryBuilder() | ||
->select('inverse') | ||
->from(InverseSide::class, 'inverse') | ||
->andWhere('inverse.id = :id') | ||
->setParameter('id', 'inverse') | ||
->getQuery() | ||
->getSingleResult(); | ||
|
||
self::assertInstanceOf(InverseSide::class, $fetchedInverse); | ||
self::assertInstanceOf(OwningSide::class, $fetchedInverse->owning); | ||
|
||
$this->assertSQLEquals( | ||
'select o0_.id as id_0 from one_to_one_inverse_side_load_inverse o0_ where o0_.id = ?', | ||
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql'] | ||
); | ||
|
||
$this->assertSQLEquals( | ||
'select t0.id as id_1, t0.inverse as inverse_2 from one_to_one_inverse_side_load_owning t0 WHERE t0.inverse = ?', | ||
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] | ||
); | ||
} | ||
} |