forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
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: Set column length explicitly (doctrine#11393) Add missing import Remove unused variable (doctrine#11391) [Documentation] Removing "Doctrine Mapping Types" ... (doctrine#11384) [doctrineGH-11185] Bugfix: do not use collection batch loading for indexBy assocations. (doctrine#11380) Improve lazy ghost performance by avoiding self-referencing closure. (doctrine#11376)
- Loading branch information
Showing
10 changed files
with
149 additions
and
63 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
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
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
#[ORM\Table('gh11149_eager_product')] | ||
class EagerProduct | ||
{ | ||
#[ORM\Id] | ||
#[ORM\Column] | ||
public int $id; | ||
|
||
/** @var Collection<string, EagerProductTranslation> */ | ||
#[ORM\OneToMany( | ||
targetEntity: EagerProductTranslation::class, | ||
mappedBy: 'product', | ||
fetch: 'EAGER', | ||
indexBy: 'locale_code', | ||
)] | ||
public Collection $translations; | ||
|
||
public function __construct(int $id) | ||
{ | ||
$this->id = $id; | ||
$this->translations = new ArrayCollection(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
<?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] | ||
private int $id; | ||
|
||
#[ORM\ManyToOne(inversedBy: 'translations')] | ||
#[ORM\JoinColumn(nullable: false)] | ||
public EagerProduct $product; | ||
|
||
#[ORM\ManyToOne] | ||
#[ORM\JoinColumn(name: 'locale_code', referencedColumnName: 'code', nullable: false)] | ||
public Locale $locale; | ||
|
||
public function __construct(int $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,21 @@ | ||
<?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(length: 5)] | ||
public string $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