-
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.
Merge pull request #11090 from dbannik/2.17.x-failed-getting-entity-w…
…ith-fetch-eager [2.17.x] Failed getting entity with fetch eager property
- Loading branch information
Showing
5 changed files
with
150 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
tests/Tests/Models/AbstractFetchEager/AbstractRemoteControl.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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\Table(name="abstract_fetch_eager_remote_control") | ||
* @ORM\InheritanceType("SINGLE_TABLE") | ||
* @ORM\DiscriminatorColumn(name="type", type="string") | ||
* @ORM\DiscriminatorMap({"mobile"="MobileRemoteControl"}) | ||
*/ | ||
abstract class AbstractRemoteControl | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* /** | ||
* | ||
* @ORM\Column(type="string") | ||
* | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity="User", mappedBy="remoteControl", fetch="EAGER") | ||
* | ||
* @var Collection<User> | ||
*/ | ||
public $users; | ||
|
||
public function __construct(string $name) | ||
{ | ||
$this->name = $name; | ||
$this->users = new ArrayCollection(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Tests/Models/AbstractFetchEager/MobileRemoteControl.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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
*/ | ||
class MobileRemoteControl extends AbstractRemoteControl | ||
{ | ||
} |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\Table(name="abstract_fetch_eager_user") | ||
*/ | ||
class User | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="AbstractRemoteControl", inversedBy="users") | ||
* @ORM\JoinColumn(nullable=false) | ||
* | ||
* @var AbstractRemoteControl | ||
*/ | ||
public $remoteControl; | ||
|
||
public function __construct(AbstractRemoteControl $control) | ||
{ | ||
$this->remoteControl = $control; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\Tests\Models\AbstractFetchEager\AbstractRemoteControl; | ||
use Doctrine\Tests\Models\AbstractFetchEager\MobileRemoteControl; | ||
use Doctrine\Tests\Models\AbstractFetchEager\User; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
final class AbstractFetchEagerTest extends OrmFunctionalTestCase | ||
{ | ||
public function testWithAbstractFetchEager(): void | ||
{ | ||
$this->createSchemaForModels( | ||
AbstractRemoteControl::class, | ||
User::class | ||
); | ||
|
||
$control = new MobileRemoteControl('smart'); | ||
$user = new User($control); | ||
|
||
$entityManage = $this->getEntityManager(); | ||
|
||
$entityManage->persist($control); | ||
$entityManage->persist($user); | ||
$entityManage->flush(); | ||
$entityManage->clear(); | ||
|
||
$user = $entityManage->find(User::class, $user->id); | ||
|
||
self::assertNotNull($user); | ||
self::assertEquals('smart', $user->remoteControl->name); | ||
self::assertTrue($user->remoteControl->users->contains($user)); | ||
} | ||
} |