Skip to content

Commit

Permalink
Changing the logic for obtaining an identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
dbannik committed Feb 13, 2024
1 parent c0b12e5 commit 39ea503
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
9 changes: 5 additions & 4 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -3252,11 +3252,12 @@ private function eagerLoadCollections(array $collections, array $mapping): void
foreach ($found as $targetValue) {
$sourceEntity = $targetProperty->getValue($targetValue);

if ($sourceEntity === null) {
if ($sourceEntity === null && isset($targetClass->associationMappings[$mappedBy]['joinColumns'])) {
$data = $this->getOriginalEntityData($targetValue);
$id = array_map(static function (array $joinColumn) use ($data) {
return $data[$joinColumn['name']];
}, $targetClass->associationMappings[$mappedBy]['joinColumns']);
$id = [];
foreach ($targetClass->associationMappings[$mappedBy]['joinColumns'] as $joinColumn) {
$id[] = $data[$joinColumn['name']];
}
} else {
$id = $this->identifierFlattener->flattenIdentifier($class, $class->getIdentifierValues($sourceEntity));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"mobile"="MobileRemoteControl"})
* @ORM\Table(name="test_control")
*/
abstract class AbstractRemoveControl
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/**
* @ORM\Entity()
* @ORM\Table(name="test_user")
*/
class User
{
Expand Down
37 changes: 19 additions & 18 deletions tests/Doctrine/Tests/ORM/Functional/AbstractFetchEagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\Performance\EntityManagerFactory;
use Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager\AbstractRemoveControl;
use Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager\MobileRemoteControl;
use Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager\User;
use Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager\AbstractRemoveControl as AbstractRemoveControlWithoutFetchEager;
use Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager\MobileRemoteControl as MobileRemoteControlWithoutFetchEager;
use Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager\User as UserWithoutFetchEager;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\TestCase;

final class AbstractFetchEagerTest extends OrmFunctionalTestCase
final class AbstractFetchEagerTest extends TestCase
{
public function testWithAbstractFetchEager(): void
{
$this->createSchemaForModels(
$entityManager = EntityManagerFactory::getEntityManager([
AbstractRemoveControl::class,
User::class
);
User::class,
]);

$control = new MobileRemoteControl('smart');
$user = new User($control);

$this->_em->persist($control);
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$entityManager->persist($control);
$entityManager->persist($user);
$entityManager->flush();
$entityManager->clear();

$user = $this->_em->find(User::class, $user->id);
$user = $entityManager->find(User::class, $user->id);

self::assertNotNull($user);
self::assertEquals('smart', $user->remoteControl->name);
Expand All @@ -38,20 +39,20 @@ public function testWithAbstractFetchEager(): void

public function testWithoutAbstractFetchEager(): void
{
$this->createSchemaForModels(
$entityManager = EntityManagerFactory::getEntityManager([
AbstractRemoveControlWithoutFetchEager::class,
UserWithoutFetchEager::class
);
UserWithoutFetchEager::class,
]);

$control = new MobileRemoteControlWithoutFetchEager('smart');
$user = new UserWithoutFetchEager($control);

$this->_em->persist($control);
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$entityManager->persist($control);
$entityManager->persist($user);
$entityManager->flush();
$entityManager->clear();

$user = $this->_em->find(UserWithoutFetchEager::class, $user->id);
$user = $entityManager->find(UserWithoutFetchEager::class, $user->id);

self::assertNotNull($user);
self::assertEquals('smart', $user->remoteControl->name);
Expand Down

0 comments on commit 39ea503

Please sign in to comment.