-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2 Does this work with Collections?
- added two workarounds - adapted tests - adapted readme
- Loading branch information
1 parent
fa62291
commit d48969d
Showing
8 changed files
with
365 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
|
||
namespace Metaclass\FilterBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* Class TestRelated | ||
* @package Metaclass\FilterBundle\Entity | ||
* @ORM\Entity | ||
*/ | ||
class TestRelated | ||
{ | ||
/** | ||
* @var int The entity Id | ||
* | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
public $id = 0; | ||
|
||
/** | ||
* @var float | ||
* @ORM\Column(type="float") | ||
*/ | ||
public $numb = 0.0; | ||
|
||
/** | ||
* @var string | ||
* @ORM\Column | ||
*/ | ||
public $text; | ||
|
||
/** | ||
* @var \DateTime|null | ||
* @ORM\Column(type="date", nullable=true) | ||
*/ | ||
public $dd; | ||
|
||
/** | ||
* @var bool|null | ||
* @ORM\Column(type="boolean", nullable=true) | ||
*/ | ||
public $bool; | ||
|
||
/** | ||
* @var TestEntity | ||
* @ORM\ManyToOne(targetEntity="Metaclass\FilterBundle\Entity\TestEntity", inversedBy="toMany") | ||
* @ORM\JoinColumn(referencedColumnName="id", nullable=false) | ||
*/ | ||
public $testEntity; | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace Metaclass\FilterBundle\Filter; | ||
|
||
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ContextAwareFilterInterface; | ||
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface; | ||
use Doctrine\ORM\QueryBuilder; | ||
use Doctrine\ORM\Query\Expr\Join; | ||
|
||
/** | ||
* Filter to be added as the first ApiFilter of an ApiResource. | ||
* Adds a Fake Left Join to the QueryBuilder so that the filters that come | ||
* afterwards that use \ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryBuilderHelper::addJoinOnce | ||
* will use Left Joins instead of Inner Joins. | ||
* WARNING: This changes the behavior of ExistsFilter =false, consider | ||
* using ExistFilter included in this bundle instead. | ||
*/ | ||
class AddFakeLeftJoin implements ContextAwareFilterInterface | ||
{ | ||
public static $FAKEJOIN = "Fake.kdoejfndnsklslwkweofdjhsd"; | ||
|
||
/** {@inheritdoc } */ | ||
public function getDescription(string $resourceClass): array | ||
{ | ||
// No description | ||
return []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function apply( | ||
QueryBuilder $queryBuilder, | ||
QueryNameGeneratorInterface $queryNameGenerator, | ||
string $resourceClass, | ||
string $operationName = null, | ||
array $context = [] | ||
) { | ||
// $queryBuilder->leftJoin(self::$FAKEJOIN, null); | ||
$rootAliases = $queryBuilder->getRootAliases(); | ||
$join = new Join( | ||
Join::LEFT_JOIN, | ||
self::$FAKEJOIN | ||
); | ||
$queryBuilder->add('join', [$rootAliases[0] => $join], true); | ||
} | ||
} |
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
Oops, something went wrong.