-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#6759 showstopper one-to-one inverse not being loaded with correct identifier restrictions when defining joinColumn
#6760
Merged
lcobucci
merged 7 commits into
master
from
fix/#6759-showstopper-one-to-one-inverse-not-being-loaded-with-correct-identifier-restrictions
Oct 8, 2017
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5f99cad
Failing test - inverse side OneToOne loaded without identifier condition
janlanger 6ba2d1c
#6759 cleaning up test case body
Ocramius d831f4f
#6759 segregating test models into their own namespace
Ocramius 83e00d5
#6759 cleaning up test case, using new models from the isolated names…
Ocramius dd12ba8
#6759 avoiding reuse of the `$identifier` variable when constructing …
Ocramius 3dd7eb5
#6759 removing outdated comment as per @alcaeus' review
Ocramius 66f903a
#6759 remove `#` symbol from `@group` annotation as per @lcobucci's r…
Ocramius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'] | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the other test cases don't have the
#
, I'd remove it for consistency.