Skip to content

Commit

Permalink
Add static::joinXXX methods
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbeaujean committed Feb 5, 2024
1 parent 29365f1 commit d4d2f0b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Generator/RepositoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ private function generateRepository(array $allMetadata, string $bundleName, Clas

foreach ($associationMappings as $associationMapping) {
$targetEntityMetadata = $allMetadata[$associationMapping['targetEntity']];
$renderedTemplate .= $this->templateService->renderAssociation($associationMapping, $entityDql, $targetEntityMetadata);

$renderedTemplate .= $this->templateService->renderAssociation(
$associationMapping,
$entityDql,
$targetEntityMetadata,
$this->configurator->getEntityDqlName($associationMapping['targetEntity']),
);
}

//get the bottom template
Expand Down
9 changes: 7 additions & 2 deletions Generator/TemplateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ public function renderTopClass(string $extendClass, string $namespace, string $e
return $this->twig->render($this->topRepositoryTemple, $topClassparameter);
}

public function renderAssociation(array $associationMapping, string $entityDql, ClassMetadata $targetEntityMetadata): string
{
public function renderAssociation(
array $associationMapping,
string $entityDql,
ClassMetadata $targetEntityMetadata,
string $entityDqlTargeted,
): string {
$idType = null;

if (isset($targetEntityMetadata->fieldMappings['id'])) {
Expand All @@ -48,6 +52,7 @@ public function renderAssociation(array $associationMapping, string $entityDql,
'columnDql' => $fieldName,
'idType' => $idType,
'targetEntity' => $associationMapping['targetEntity'],
'entityDqlTargeted' => $entityDqlTargeted,
);

return $this->twig->render($this->associationTemplate, $parameters);
Expand Down
7 changes: 7 additions & 0 deletions Resources/views/Generator/AssociationTemplate.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,10 @@

return $qb;
}

public static function join{{ column }}(QueryBuilder $qb, $entityName = '{{ entityDql }}', $columnName = '{{ columnDql }}', $entityDqlTargeted = '{{ entityDqlTargeted }}'): QueryBuilder
{
$qb->join($entityName.'.'.$columnName, $entityDqlTargeted);

return $qb;
}

0 comments on commit d4d2f0b

Please sign in to comment.