-
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.
Skip joined entity creation for empty relation (#10889)
- Loading branch information
1 parent
59c8bc0
commit 75912dc
Showing
2 changed files
with
115 additions
and
4 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
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,107 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
/** | ||
* @see https://github.com/doctrine/orm/issues/10889 | ||
* | ||
* @group GH10889 | ||
*/ | ||
class GH10889Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->createSchemaForModels( | ||
GH10889User::class, | ||
GH10889Item::class, | ||
GH10889Box::class | ||
); | ||
} | ||
|
||
public function testIssue(): void | ||
{ | ||
$user = new GH10889User(); | ||
$box = new GH10889Box($user, null); | ||
|
||
$this->_em->persist($user); | ||
$this->_em->persist($box); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
/** @var list<GH10889Box> $boxes */ | ||
$boxes = $this->_em | ||
->getRepository(GH10889Box::class) | ||
->createQueryBuilder('box') | ||
->leftJoin('box.item', 'item')->addSelect('item') | ||
->getQuery() | ||
->getResult(); | ||
|
||
$this->assertArrayHasKey(0, $boxes); | ||
$this->assertEquals(1, $boxes[0]->user->id); | ||
$this->assertNull($boxes[0]->item); | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH10889User | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH10889Item | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH10889Box | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\OneToOne(targetEntity="GH10889User") | ||
* | ||
* @var GH10889User | ||
*/ | ||
public $user; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="GH10889Item") | ||
* | ||
* @var GH10889Item|null | ||
*/ | ||
public $item; | ||
|
||
public function __construct(GH10889User $user, ?GH10889Item $item) | ||
{ | ||
$this->user = $user; | ||
$this->item = $item; | ||
} | ||
} |