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.
Fix Hydration when use ManyToMany[indexBy]
The bug related (doctrine#11694) and fixed mapping of sql column alias to field in entity (doctrine#11783) and invalidate cache [cache/persisted/entity|cache/persisted/collection] when sql filter changes
- Loading branch information
1 parent
c12fd2c
commit 47a3015
Showing
11 changed files
with
230 additions
and
15 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
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
43 changes: 43 additions & 0 deletions
43
tests/Tests/ORM/Functional/Ticket/SwitchContextWithFilterAndIndexedRelation/Category.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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\SwitchContextWithFilterAndIndexedRelation; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="Category_Master") | ||
*/ | ||
class Category | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\Column(type="string") | ||
* | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @ORM\Column(type="string") | ||
* | ||
* @var string | ||
*/ | ||
public $type; | ||
|
||
public function __construct(string $name, string $type) | ||
{ | ||
$this->name = $name; | ||
$this->type = $type; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ORM/Functional/Ticket/SwitchContextWithFilterAndIndexedRelation/CategoryTypeSQLFilter.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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\SwitchContextWithFilterAndIndexedRelation; | ||
|
||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Doctrine\ORM\Query\Filter\SQLFilter; | ||
|
||
use function sprintf; | ||
|
||
class CategoryTypeSQLFilter extends SQLFilter | ||
{ | ||
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias): string | ||
{ | ||
if ($targetEntity->getName() === Category::class) { | ||
return sprintf('%s.%s = %s', $targetTableAlias, $targetEntity->fieldMappings['type']['fieldName'], $this->getParameter('type')); | ||
} | ||
|
||
return ''; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...sts/ORM/Functional/Ticket/SwitchContextWithFilterAndIndexedRelation/ChangeFiltersTest.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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\SwitchContextWithFilterAndIndexedRelation; | ||
|
||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
final class ChangeFiltersTest extends OrmFunctionalTestCase | ||
{ | ||
private const COMPANY_A = 'A'; | ||
private const CAT_BAR = 'bar'; | ||
private const CAT_FOO = 'foo'; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpEntitySchema([ | ||
Company::class, | ||
Category::class, | ||
]); | ||
} | ||
|
||
private function prepareData(): void | ||
{ | ||
$cat1 = new Category('cat1', self::CAT_FOO); | ||
$cat2 = new Category('cat2', self::CAT_BAR); | ||
$companyA = new Company(self::COMPANY_A, [$cat1, $cat2]); | ||
|
||
$this->_em->persist($cat1); | ||
$this->_em->persist($cat2); | ||
$this->_em->persist($companyA); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
} | ||
|
||
public function testIndexAliasUpdatedWithUpdatedFilter(): void | ||
{ | ||
$this->prepareData(); | ||
|
||
$company = $this->_em->getRepository(Company::class)->findOneBy([]); | ||
|
||
self::assertCount(2, $company->categories); | ||
self::assertEquals([self::CAT_FOO, self::CAT_BAR], $company->categories->map(static function (Category $c): string { | ||
return $c->type; | ||
})->getValues()); | ||
|
||
$this->_em->clear(); | ||
$this->_em->getConfiguration()->addFilter(CategoryTypeSQLFilter::class, CategoryTypeSQLFilter::class); | ||
$this->_em->getFilters()->enable(CategoryTypeSQLFilter::class)->setParameter('type', self::CAT_FOO); | ||
|
||
$company = $this->_em->getRepository(Company::class)->findOneBy([]); | ||
|
||
self::assertCount(1, $company->categories); | ||
self::assertEquals([self::CAT_FOO], $company->categories->map(static function (Category $c): string { | ||
return $c->type; | ||
})->getValues()); | ||
} | ||
} |
Oops, something went wrong.