diff --git a/Generator/RepositoryGenerator.php b/Generator/RepositoryGenerator.php index c0da640..5b76ae9 100644 --- a/Generator/RepositoryGenerator.php +++ b/Generator/RepositoryGenerator.php @@ -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 diff --git a/Generator/TemplateService.php b/Generator/TemplateService.php index 15eb55e..7faf05d 100644 --- a/Generator/TemplateService.php +++ b/Generator/TemplateService.php @@ -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'])) { @@ -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); diff --git a/Resources/views/Generator/AssociationTemplate.html.twig b/Resources/views/Generator/AssociationTemplate.html.twig index b683997..0325aa4 100644 --- a/Resources/views/Generator/AssociationTemplate.html.twig +++ b/Resources/views/Generator/AssociationTemplate.html.twig @@ -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; + }