-
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.
* 2.19.x: [Documentation] Removing "Doctrine Mapping Types" ... (#11384) [GH-11185] Bugfix: do not use collection batch loading for indexBy assocations. (#11380) Improve lazy ghost performance by avoiding self-referencing closure. (#11376)
- Loading branch information
Showing
9 changed files
with
177 additions
and
61 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
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
41 changes: 41 additions & 0 deletions
41
tests/Tests/ORM/Functional/Ticket/GH11149/EagerProduct.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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table("gh11149_eager_product") | ||
*/ | ||
class EagerProduct | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\OneToMany( | ||
* targetEntity=EagerProductTranslation::class, | ||
* mappedBy="product", | ||
* fetch="EAGER", | ||
* indexBy="locale_code" | ||
* ) | ||
* | ||
* @var Collection<string, EagerProductTranslation> | ||
*/ | ||
public $translations; | ||
|
||
public function __construct(int $id) | ||
{ | ||
$this->id = $id; | ||
$this->translations = new ArrayCollection(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
tests/Tests/ORM/Functional/Ticket/GH11149/EagerProductTranslation.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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table("gh11149_eager_product_translation") | ||
*/ | ||
class EagerProductTranslation | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity=EagerProduct::class, inversedBy="translations") | ||
* @ORM\JoinColumn(nullable=false) | ||
* | ||
* @var EagerProduct | ||
*/ | ||
public $product; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity=Locale::class) | ||
* @ORM\JoinColumn(name="locale_code", referencedColumnName="code", nullable=false) | ||
* | ||
* @var Locale | ||
*/ | ||
public $locale; | ||
|
||
public function __construct($id, EagerProduct $product, Locale $locale) | ||
{ | ||
$this->id = $id; | ||
$this->product = $product; | ||
$this->locale = $locale; | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
use Doctrine\ORM\PersistentCollection; | ||
use Doctrine\Persistence\Proxy; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
class GH11149Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpEntitySchema([ | ||
Locale::class, | ||
EagerProduct::class, | ||
EagerProductTranslation::class, | ||
]); | ||
} | ||
|
||
public function testFetchEagerModeWithIndexBy(): void | ||
{ | ||
// Load entities into database | ||
$this->_em->persist($product = new EagerProduct(11149)); | ||
$this->_em->persist($locale = new Locale('fr_FR')); | ||
$this->_em->persist(new EagerProductTranslation(11149, $product, $locale)); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
// Fetch entity from database | ||
$product = $this->_em->find(EagerProduct::class, 11149); | ||
|
||
// Assert associated entity is loaded eagerly | ||
static::assertInstanceOf(EagerProduct::class, $product); | ||
static::assertInstanceOf(PersistentCollection::class, $product->translations); | ||
static::assertTrue($product->translations->isInitialized()); | ||
static::assertCount(1, $product->translations); | ||
|
||
// Assert associated entity is indexed by given property | ||
$translation = $product->translations->get('fr_FR'); | ||
static::assertInstanceOf(EagerProductTranslation::class, $translation); | ||
static::assertNotInstanceOf(Proxy::class, $translation); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table("gh11149_locale") | ||
*/ | ||
class Locale | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="string") | ||
* | ||
* @var string | ||
*/ | ||
public $code; | ||
|
||
public function __construct(string $code) | ||
{ | ||
$this->code = $code; | ||
} | ||
} |
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