Skip to content

Commit

Permalink
Generate existsByXXXXX
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbeaujean committed Apr 18, 2024
1 parent 6dbb8aa commit f39e348
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Resources/views/Generator/ColumnTemplate.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,14 @@

return static::getQueryBuilderSingleResult($qb);
}

public function existsBy{{ column }}(
mixed $value,
): bool {
$qb = $this->getNewQueryBuilder();
static::filterBy{{ column }}($qb, $value);

return static::existsByQueryBuilder(
qb: $qb,
);
}
33 changes: 33 additions & 0 deletions tests/Repository/MyClassRepositoryBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ public function findOneById(
return static::getQueryBuilderSingleResult($qb);
}

public function existsById(
mixed $value,
): bool {
$qb = $this->getNewQueryBuilder();
static::filterById($qb, $value);

return static::existsByQueryBuilder(
qb: $qb,
);
}

public static function filterByNumber(QueryBuilder $qb, $value, $operator = Comparison::EQ, $entityName = 'myClass', $columnName = 'number'): QueryBuilder
{
if ($value === null) {
Expand Down Expand Up @@ -317,6 +328,17 @@ public function findOneByNumber(
return static::getQueryBuilderSingleResult($qb);
}

public function existsByNumber(
mixed $value,
): bool {
$qb = $this->getNewQueryBuilder();
static::filterByNumber($qb, $value);

return static::existsByQueryBuilder(
qb: $qb,
);
}

public static function filterByName(QueryBuilder $qb, $value, $operator = Comparison::EQ, $entityName = 'myClass', $columnName = 'name'): QueryBuilder
{
if ($value === null) {
Expand Down Expand Up @@ -390,6 +412,17 @@ public function findOneByName(
return static::getQueryBuilderSingleResult($qb);
}

public function existsByName(
mixed $value,
): bool {
$qb = $this->getNewQueryBuilder();
static::filterByName($qb, $value);

return static::existsByQueryBuilder(
qb: $qb,
);
}

public static function filterByForeignClasses(QueryBuilder $qb, $value, $operator = Comparison::EQ, $entityName = 'myClass', $columnName = 'foreignClasses'): QueryBuilder
{
//get a uniq index
Expand Down
33 changes: 33 additions & 0 deletions tests/Service/ExpectedMyClassRepositoryBase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ class MyClassRepositoryBase extends \Doctrine\Bundle\DoctrineBundle\Repository\S
return static::getQueryBuilderSingleResult($qb);
}

public function existsById(
mixed $value,
): bool {
$qb = $this->getNewQueryBuilder();
static::filterById($qb, $value);

return static::existsByQueryBuilder(
qb: $qb,
);
}

public static function filterByNumber(QueryBuilder $qb, $value, $operator = Comparison::EQ, $entityName = 'myClass', $columnName = 'number'): QueryBuilder
{
if ($value === null) {
Expand Down Expand Up @@ -317,6 +328,17 @@ class MyClassRepositoryBase extends \Doctrine\Bundle\DoctrineBundle\Repository\S
return static::getQueryBuilderSingleResult($qb);
}

public function existsByNumber(
mixed $value,
): bool {
$qb = $this->getNewQueryBuilder();
static::filterByNumber($qb, $value);

return static::existsByQueryBuilder(
qb: $qb,
);
}

public static function filterByName(QueryBuilder $qb, $value, $operator = Comparison::EQ, $entityName = 'myClass', $columnName = 'name'): QueryBuilder
{
if ($value === null) {
Expand Down Expand Up @@ -390,6 +412,17 @@ class MyClassRepositoryBase extends \Doctrine\Bundle\DoctrineBundle\Repository\S
return static::getQueryBuilderSingleResult($qb);
}

public function existsByName(
mixed $value,
): bool {
$qb = $this->getNewQueryBuilder();
static::filterByName($qb, $value);

return static::existsByQueryBuilder(
qb: $qb,
);
}

public static function filterByForeignClasses(QueryBuilder $qb, $value, $operator = Comparison::EQ, $entityName = 'myClass', $columnName = 'foreignClasses'): QueryBuilder
{
//get a uniq index
Expand Down

0 comments on commit f39e348

Please sign in to comment.