-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(doctrine): searchfilter with nested custom identifiers (#5760)
- Loading branch information
Showing
16 changed files
with
580 additions
and
8 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
41 changes: 41 additions & 0 deletions
41
tests/Fixtures/TestBundle/ApiResource/Issue5605/MainResource.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,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5605; | ||
|
||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; | ||
use ApiPlatform\Doctrine\Orm\State\Options; | ||
use ApiPlatform\Metadata\ApiFilter; | ||
use ApiPlatform\Metadata\ApiProperty; | ||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\GetCollection; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyWithSubEntity; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\State\Issue5605\MainResourceProvider; | ||
|
||
#[ApiResource( | ||
operations : [ | ||
new Get(uriTemplate: '/dummy_with_subresource/{id}', uriVariables: ['id']), | ||
new GetCollection(uriTemplate: '/dummy_with_subresource'), | ||
], | ||
provider : MainResourceProvider::class, | ||
stateOptions: new Options(entityClass: DummyWithSubEntity::class) | ||
)] | ||
#[ApiFilter(SearchFilter::class, properties: ['subEntity'])] | ||
class MainResource | ||
{ | ||
#[ApiProperty(identifier: true)] | ||
public int $id; | ||
public string $name; | ||
public SubResource $subResource; | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Fixtures/TestBundle/ApiResource/Issue5605/SubResource.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,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5605; | ||
|
||
use ApiPlatform\Doctrine\Orm\State\Options; | ||
use ApiPlatform\Metadata\ApiProperty; | ||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummySubEntity; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\State\Issue5605\SubResourceProvider; | ||
|
||
#[ApiResource( | ||
operations : [ | ||
new Get( | ||
uriTemplate: '/dummy_subresource/{strId}', | ||
uriVariables: ['strId'] | ||
), | ||
], | ||
provider: SubResourceProvider::class, | ||
stateOptions: new Options(entityClass: DummySubEntity::class) | ||
)] | ||
class SubResource | ||
{ | ||
#[ApiProperty(identifier: true)] | ||
public string $strId; | ||
|
||
public string $name; | ||
} |
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,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
class DummySubEntity | ||
{ | ||
#[ORM\Id] | ||
#[ORM\Column(type: 'string')] | ||
private string $strId; | ||
|
||
#[ORM\Column] | ||
private string $name; | ||
|
||
#[ORM\OneToOne(inversedBy: 'subEntity', cascade: ['persist'])] | ||
private ?DummyWithSubEntity $mainEntity = null; | ||
|
||
public function __construct($strId, $name) | ||
{ | ||
$this->strId = $strId; | ||
$this->name = $name; | ||
} | ||
|
||
public function getStrId(): string | ||
{ | ||
return $this->strId; | ||
} | ||
|
||
public function getMainEntity(): ?DummyWithSubEntity | ||
{ | ||
return $this->mainEntity; | ||
} | ||
|
||
public function setMainEntity(DummyWithSubEntity $mainEntity): void | ||
{ | ||
$this->mainEntity = $mainEntity; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): void | ||
{ | ||
$this->name = $name; | ||
} | ||
} |
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 | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
class DummyWithSubEntity | ||
{ | ||
#[ORM\Id] | ||
#[ORM\Column(type: 'integer')] | ||
#[ORM\GeneratedValue(strategy: 'AUTO')] | ||
private int $id; | ||
|
||
#[ORM\Column] | ||
private string $name; | ||
|
||
#[ORM\OneToOne(mappedBy: 'mainEntity', cascade: ['persist'], fetch: 'EAGER')] | ||
private ?DummySubEntity $subEntity = null; | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): void | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function getSubEntity(): ?DummySubEntity | ||
{ | ||
return $this->subEntity; | ||
} | ||
|
||
public function setSubEntity(?DummySubEntity $subEntity): void | ||
{ | ||
if (null !== $subEntity && $subEntity->getMainEntity() !== $this) { | ||
$subEntity->setMainEntity($this); | ||
} | ||
|
||
$this->subEntity = $subEntity; | ||
} | ||
} |
Oops, something went wrong.