Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Brajkovic committed Feb 3, 2025
1 parent 10ea8c0 commit a86d234
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
14 changes: 11 additions & 3 deletions tests/Tests/Models/EagerFetchedCompositeOneToMany/RootEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ class RootEntity
*/
private $secondLevel;

/**
* @ORM\OneToMany(mappedBy="root", targetEntity=SecondLevelWithoutCompositePrimaryKey::class, fetch="EAGER")
*
* @var Collection<int, SecondLevelWithoutCompositePrimaryKey>
*/
private $anotherSecondLevel;

public function __construct(int $id, string $other)
{
$this->otherKey = $other;
$this->secondLevel = new ArrayCollection();
$this->id = $id;
$this->otherKey = $other;
$this->secondLevel = new ArrayCollection();
$this->anotherSecondLevel = new ArrayCollection();
$this->id = $id;
}

public function getId(): ?int
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\EagerFetchedCompositeOneToMany;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class SecondLevelWithoutCompositePrimaryKey
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer", nullable=false)
*
* @var int|null
*/
private $id;

/**
* @ORM\ManyToOne(targetEntity=RootEntity::class, inversedBy="anotherSecondLevel")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="root_id", referencedColumnName="id"),
* @ORM\JoinColumn(name="root_other_key", referencedColumnName="other_key")
* })
*
* @var RootEntity
*/
private $root;

public function __construct(RootEntity $upper)
{
$this->root = $upper;
}

public function getId(): ?int
{
return $this->id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use Doctrine\Tests\Models\EagerFetchedCompositeOneToMany\RootEntity;
use Doctrine\Tests\Models\EagerFetchedCompositeOneToMany\SecondLevel;
use Doctrine\Tests\Models\EagerFetchedCompositeOneToMany\SecondLevelWithoutCompositePrimaryKey;
use Doctrine\Tests\OrmFunctionalTestCase;

final class EagerFetchOneToManyWithCompositeKeyTest extends OrmFunctionalTestCase
{
/** @ticket 11154 */
public function testItDoesNotThrowAnExceptionWhenTriggeringALoad(): void
{
$this->setUpEntitySchema([RootEntity::class, SecondLevel::class]);
$this->setUpEntitySchema([RootEntity::class, SecondLevel::class, SecondLevelWithoutCompositePrimaryKey::class]);

$a1 = new RootEntity(1, 'A');

Expand Down

0 comments on commit a86d234

Please sign in to comment.