getRepository(Prehistoric::class); //$repoBib = $em->getRepository(Bibliography::class); $records = $repo->findBy([], ['label' => 'ASC']); // Terrible? N+1.. foreach ($records as $key => $record) { $id = $record->getId(); $record->setLat($repo->coordinates($id)['lat']); $record->setLng($repo->coordinates($id)['lng']); $repoImg = $em->getRepository(Image::class); $images = $repoImg->findBy( ['prehistoric' => $record->getId()], ['sequence' => 'ASC'] ); $record->setImages($images); $records[$key] = $record; } return $this->json([ 'message' => 'All records for prehistoric assets', 'records' => $records ], ); } #[Route('/prehistoric/{id<\d+>}', name: 'app_prehistoric_record')] public function record(Prehistoric $prehistoric, EntityManagerInterface $em): JsonResponse { $repo = $em->getRepository(Prehistoric::class); $coordinates = $repo->coordinates($prehistoric->getId()); //$repo = $em->getRepository(Bibliography::class); //$biblio = $repo->findAllByNotConserved($prehistoric->getId()); //$notConserved->setBibliographies($biblio); $prehistoric->setLat($coordinates['lat']); $prehistoric->setLng($coordinates['lng']); $repo = $em->getRepository(Image::class); $images = $repo->findBy( ['prehistoric' => $prehistoric->getId()], ['sequence' => 'ASC'] ); $prehistoric->setImages($images); return $this->json($prehistoric); } }