Skip to content

Commit

Permalink
Association: filterIn Allow direct values and entity
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbeaujean committed Apr 29, 2024
1 parent f39e348 commit 6f3e4ef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Resources/views/Generator/AssociationTemplate.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@

foreach ($values as $value) {
if ($value !== null) {
$ids[] = $value->getId();
// by default we use the value
$id = $value;
if ($value instanceof \{{targetEntity}}) {
$id = $value->getId();
}

$ids[] = $id;
} else {
$orNull = ' OR '.$entityName.'.'.$columnName.' IS NULL';
}
Expand Down
8 changes: 7 additions & 1 deletion tests/Repository/MyClassRepositoryBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,13 @@ public static function filterInForeignClasses(QueryBuilder $qb, $values, $entity

foreach ($values as $value) {
if ($value !== null) {
$ids[] = $value->getId();
// by default we use the value
$id = $value;
if ($value instanceof \Tbn\QueryBuilderRepositoryGeneratorBundle\Tests\Entity\ForeignClass) {
$id = $value->getId();
}

$ids[] = $id;
} else {
$orNull = ' OR '.$entityName.'.'.$columnName.' IS NULL';
}
Expand Down
8 changes: 7 additions & 1 deletion tests/Service/ExpectedMyClassRepositoryBase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,13 @@ class MyClassRepositoryBase extends \Doctrine\Bundle\DoctrineBundle\Repository\S

foreach ($values as $value) {
if ($value !== null) {
$ids[] = $value->getId();
// by default we use the value
$id = $value;
if ($value instanceof \Tbn\QueryBuilderRepositoryGeneratorBundle\Tests\Entity\ForeignClass) {
$id = $value->getId();
}

$ids[] = $id;
} else {
$orNull = ' OR '.$entityName.'.'.$columnName.' IS NULL';
}
Expand Down

0 comments on commit 6f3e4ef

Please sign in to comment.