Skip to content

Commit

Permalink
Fix scope uncasting in the ManyToMany relation
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jul 26, 2023
1 parent 1a2f48a commit f0b7197
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/Relation/ManyToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ class ManyToMany extends Relation\AbstractRelation
protected FactoryInterface $factory;
private HeapInterface $heap;

public function __construct(ORMInterface $orm, string $role, string $name, string $target, array $schema)
{
public function __construct(
ORMInterface $orm,
private string $role,
string $name,
string $target,
array $schema
) {
parent::__construct($orm, $role, $name, $target, $schema);
$this->heap = $orm->getHeap();
$this->sourceProvider = $orm->getService(SourceProviderInterface::class);
Expand Down Expand Up @@ -287,7 +292,7 @@ public function resolve(ReferenceInterface $reference, bool $load): ?iterable
$root->linkNode('output', $node);

// emulate presence of parent entity
$root->parseRow(0, $this->mapperProvider->getMapper($reference->getRole())->uncast($scope));
$root->parseRow(0, $this->mapperProvider->getMapper($this->role)->uncast($scope));

$iterator = $query->getIterator();
foreach ($iterator as $row) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public function testSelect(): void

$user = $this->orm->getRepository(Entity\User::class)
->findByPK($userUuid);
$groups = $user->groups;

$this->assertEquals($groupUuid, $user->groups[0]->uuid);
$this->assertEquals($groupUuid, $groups[0]->uuid);
}

private function makeTables(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Cycle\ORM\Tests\Traits\TableTrait;
use Ramsey\Uuid\Uuid;

/**
* @link https://github.com/cycle/orm/issues/416
*/
abstract class CaseTest extends BaseTest
{
use IntegrationTestTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\IntegrationTestTrait;
use Cycle\ORM\Tests\Traits\TableTrait;

/**
* @link https://github.com/cycle/orm/issues/427
*/
abstract class CaseTest extends BaseTest
{
use IntegrationTestTrait;
Expand Down

0 comments on commit f0b7197

Please sign in to comment.