getRepository(NotConserved::class); $repoBib = $em->getRepository(Bibliography::class); $records = $repo->findAll(); // Terrible? N+1.. foreach ($records as $key => $record) { $id = $record->getId(); $record->setLat($repo->coordinates($id)['lat']); $record->setLng($repo->coordinates($id)['lng']); $record->setBibliographies($repoBib->findAllByNotConserved($id)); $records[$key] = $record; } return $this->json([ 'message' => 'All records for not conserved archaeological assets', 'records' => $records ], ); } #[Route('/not_conserved/{id<\d+>}', name: 'app_not_conserved_record')] public function record(NotConserved $notConserved, EntityManagerInterface $em): JsonResponse { $repo = $em->getRepository(NotConserved::class); $coordinates = $repo->coordinates($notConserved->getId()); $repo = $em->getRepository(Bibliography::class); $biblio = $repo->findAllByNotConserved($notConserved->getId()); $notConserved->setBibliographies($biblio); $notConserved->setLat($coordinates['lat']); $notConserved->setLng($coordinates['lng']); return $this->json( $notConserved, ); } }