Skip to content

Commit 09d90bb

Browse files
ColumnTemplate: allow passing operator
1 parent 029c1bb commit 09d90bb

File tree

3 files changed

+56
-28
lines changed

3 files changed

+56
-28
lines changed

src/Resources/views/Generator/ColumnTemplate.html.twig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@
5858

5959
public function findBy{{ column }}(
6060
mixed $value,
61+
$operator = Comparison::EQ,
6162
bool $useQueryCache = false,
6263
?string $cacheId = null,
6364
array $resultCacheTags = [],
6465
): array {
6566
$qb = $this->getNewQueryBuilder();
66-
static::filterBy{{ column }}($qb, $value);
67+
static::filterBy{{ column }}($qb, $value, $operator);
6768

6869
return $this->getQueryBuilderResult(
6970
qb: $qb,
@@ -75,13 +76,14 @@
7576

7677
public function findOneBy{{ column }}(
7778
mixed $value,
79+
$operator = Comparison::EQ,
7880
bool $allowNull = false,
7981
bool $useQueryCache = false,
8082
?string $cacheId = null,
8183
array $resultCacheTags = [],
8284
): ?\{{ entityClasspath }} {
8385
$qb = $this->getNewQueryBuilder();
84-
static::filterBy{{ column }}($qb, $value);
86+
static::filterBy{{ column }}($qb, $value, $operator);
8587

8688
if ($allowNull) {
8789
return $this->getQueryBuilderOneOrNullResult(
@@ -102,12 +104,13 @@
102104

103105
public function countBy{{ column }}(
104106
mixed $value,
107+
$operator = Comparison::EQ,
105108
bool $useQueryCache = false,
106109
?string $cacheId = null,
107110
array $resultCacheTags = [],
108111
): int {
109112
$qb = $this->getNewQueryBuilder();
110-
static::filterBy{{ column }}($qb, $value);
113+
static::filterBy{{ column }}($qb, $value, $operator);
111114

112115
return static::getQueryBuilderCount(
113116
qb: $qb,
@@ -119,12 +122,13 @@
119122

120123
public function existsBy{{ column }}(
121124
mixed $value,
125+
$operator = Comparison::EQ,
122126
bool $useQueryCache = false,
123127
?string $cacheId = null,
124128
array $resultCacheTags = [],
125129
): bool {
126130
$qb = $this->getNewQueryBuilder();
127-
static::filterBy{{ column }}($qb, $value);
131+
static::filterBy{{ column }}($qb, $value, $operator);
128132

129133
return static::existsByQueryBuilder(
130134
qb: $qb,

tests/Repository/MyClassRepositoryBase.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,13 @@ public static function filterNotInId(
419419

420420
public function findById(
421421
mixed $value,
422+
$operator = Comparison::EQ,
422423
bool $useQueryCache = false,
423424
?string $cacheId = null,
424425
array $resultCacheTags = [],
425426
): array {
426427
$qb = $this->getNewQueryBuilder();
427-
static::filterById($qb, $value);
428+
static::filterById($qb, $value, $operator);
428429

429430
return $this->getQueryBuilderResult(
430431
qb: $qb,
@@ -436,13 +437,14 @@ public function findById(
436437

437438
public function findOneById(
438439
mixed $value,
440+
$operator = Comparison::EQ,
439441
bool $allowNull = false,
440442
bool $useQueryCache = false,
441443
?string $cacheId = null,
442444
array $resultCacheTags = [],
443445
): ?\Tbn\QueryBuilderRepositoryGeneratorBundle\Tests\Entity\MyClass {
444446
$qb = $this->getNewQueryBuilder();
445-
static::filterById($qb, $value);
447+
static::filterById($qb, $value, $operator);
446448

447449
if ($allowNull) {
448450
return $this->getQueryBuilderOneOrNullResult(
@@ -463,12 +465,13 @@ public function findOneById(
463465

464466
public function countById(
465467
mixed $value,
468+
$operator = Comparison::EQ,
466469
bool $useQueryCache = false,
467470
?string $cacheId = null,
468471
array $resultCacheTags = [],
469472
): int {
470473
$qb = $this->getNewQueryBuilder();
471-
static::filterById($qb, $value);
474+
static::filterById($qb, $value, $operator);
472475

473476
return static::getQueryBuilderCount(
474477
qb: $qb,
@@ -480,12 +483,13 @@ public function countById(
480483

481484
public function existsById(
482485
mixed $value,
486+
$operator = Comparison::EQ,
483487
bool $useQueryCache = false,
484488
?string $cacheId = null,
485489
array $resultCacheTags = [],
486490
): bool {
487491
$qb = $this->getNewQueryBuilder();
488-
static::filterById($qb, $value);
492+
static::filterById($qb, $value, $operator);
489493

490494
return static::existsByQueryBuilder(
491495
qb: $qb,
@@ -564,12 +568,13 @@ public static function filterNotInNumber(
564568

565569
public function findByNumber(
566570
mixed $value,
571+
$operator = Comparison::EQ,
567572
bool $useQueryCache = false,
568573
?string $cacheId = null,
569574
array $resultCacheTags = [],
570575
): array {
571576
$qb = $this->getNewQueryBuilder();
572-
static::filterByNumber($qb, $value);
577+
static::filterByNumber($qb, $value, $operator);
573578

574579
return $this->getQueryBuilderResult(
575580
qb: $qb,
@@ -581,13 +586,14 @@ public function findByNumber(
581586

582587
public function findOneByNumber(
583588
mixed $value,
589+
$operator = Comparison::EQ,
584590
bool $allowNull = false,
585591
bool $useQueryCache = false,
586592
?string $cacheId = null,
587593
array $resultCacheTags = [],
588594
): ?\Tbn\QueryBuilderRepositoryGeneratorBundle\Tests\Entity\MyClass {
589595
$qb = $this->getNewQueryBuilder();
590-
static::filterByNumber($qb, $value);
596+
static::filterByNumber($qb, $value, $operator);
591597

592598
if ($allowNull) {
593599
return $this->getQueryBuilderOneOrNullResult(
@@ -608,12 +614,13 @@ public function findOneByNumber(
608614

609615
public function countByNumber(
610616
mixed $value,
617+
$operator = Comparison::EQ,
611618
bool $useQueryCache = false,
612619
?string $cacheId = null,
613620
array $resultCacheTags = [],
614621
): int {
615622
$qb = $this->getNewQueryBuilder();
616-
static::filterByNumber($qb, $value);
623+
static::filterByNumber($qb, $value, $operator);
617624

618625
return static::getQueryBuilderCount(
619626
qb: $qb,
@@ -625,12 +632,13 @@ public function countByNumber(
625632

626633
public function existsByNumber(
627634
mixed $value,
635+
$operator = Comparison::EQ,
628636
bool $useQueryCache = false,
629637
?string $cacheId = null,
630638
array $resultCacheTags = [],
631639
): bool {
632640
$qb = $this->getNewQueryBuilder();
633-
static::filterByNumber($qb, $value);
641+
static::filterByNumber($qb, $value, $operator);
634642

635643
return static::existsByQueryBuilder(
636644
qb: $qb,
@@ -709,12 +717,13 @@ public static function filterNotInName(
709717

710718
public function findByName(
711719
mixed $value,
720+
$operator = Comparison::EQ,
712721
bool $useQueryCache = false,
713722
?string $cacheId = null,
714723
array $resultCacheTags = [],
715724
): array {
716725
$qb = $this->getNewQueryBuilder();
717-
static::filterByName($qb, $value);
726+
static::filterByName($qb, $value, $operator);
718727

719728
return $this->getQueryBuilderResult(
720729
qb: $qb,
@@ -726,13 +735,14 @@ public function findByName(
726735

727736
public function findOneByName(
728737
mixed $value,
738+
$operator = Comparison::EQ,
729739
bool $allowNull = false,
730740
bool $useQueryCache = false,
731741
?string $cacheId = null,
732742
array $resultCacheTags = [],
733743
): ?\Tbn\QueryBuilderRepositoryGeneratorBundle\Tests\Entity\MyClass {
734744
$qb = $this->getNewQueryBuilder();
735-
static::filterByName($qb, $value);
745+
static::filterByName($qb, $value, $operator);
736746

737747
if ($allowNull) {
738748
return $this->getQueryBuilderOneOrNullResult(
@@ -753,12 +763,13 @@ public function findOneByName(
753763

754764
public function countByName(
755765
mixed $value,
766+
$operator = Comparison::EQ,
756767
bool $useQueryCache = false,
757768
?string $cacheId = null,
758769
array $resultCacheTags = [],
759770
): int {
760771
$qb = $this->getNewQueryBuilder();
761-
static::filterByName($qb, $value);
772+
static::filterByName($qb, $value, $operator);
762773

763774
return static::getQueryBuilderCount(
764775
qb: $qb,
@@ -770,12 +781,13 @@ public function countByName(
770781

771782
public function existsByName(
772783
mixed $value,
784+
$operator = Comparison::EQ,
773785
bool $useQueryCache = false,
774786
?string $cacheId = null,
775787
array $resultCacheTags = [],
776788
): bool {
777789
$qb = $this->getNewQueryBuilder();
778-
static::filterByName($qb, $value);
790+
static::filterByName($qb, $value, $operator);
779791

780792
return static::existsByQueryBuilder(
781793
qb: $qb,

0 commit comments

Comments
 (0)