Use manual hydration for many-to-many to avoid problems with caching
This commit is contained in:
parent
660de08377
commit
7ab75a30fb
@ -27,23 +27,23 @@ class SiteController extends AbstractController
|
||||
$coords = $repo->coordinates($site->getId());
|
||||
$site->setLat($coords['lat']);
|
||||
$site->setLng($coords['lng']);
|
||||
$sites[$key] = $site;
|
||||
$repo = $em->getRepository(Image::class);
|
||||
$repoImg = $em->getRepository(Image::class);
|
||||
$images = new ArrayCollection(
|
||||
$repo->findBy(
|
||||
$repoImg->findBy(
|
||||
['site' => $site->getId()],
|
||||
['sequence' => 'ASC']
|
||||
)
|
||||
);
|
||||
$repo = $em->getRepository(Document::class);
|
||||
$documents = $repo->findBySite($site->getId());
|
||||
$repo = $em->getRepository(Bibliography::class);
|
||||
$bibliography = $repo->findAllBySite($site->getId());
|
||||
$repoDocs = $em->getRepository(Document::class);
|
||||
$documents = $repoDocs->findBySite($site->getId());
|
||||
$repoBib = $em->getRepository(Bibliography::class);
|
||||
$bibliography = $repoBib->findAllBySite($site->getId());
|
||||
|
||||
$site->setImages($images);
|
||||
$site->setDocuments($documents);
|
||||
$site->setBibliography($bibliography);
|
||||
$repo = $em->getRepository(Site::class);
|
||||
|
||||
$sites[$key] = $site;
|
||||
}
|
||||
|
||||
return $this->json($sites);
|
||||
|
@ -22,25 +22,35 @@ class BibliographyRepository extends ServiceEntityRepository
|
||||
*/
|
||||
public function findAllBySite(int $siteId): array
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Bibliography', 'b');
|
||||
$query = $this->getEntityManager()->createNativeQuery(
|
||||
'SELECT
|
||||
id,
|
||||
citazione,
|
||||
riferimento,
|
||||
pagine
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
b.id,
|
||||
b.citazione,
|
||||
b.riferimento,
|
||||
bs.pagine
|
||||
FROM bibliografia b
|
||||
JOIN bibliografia_sito
|
||||
ON id_bibliografia = b.id
|
||||
WHERE id_sito = :id
|
||||
ORDER BY ordine ASC',
|
||||
$rsm
|
||||
);
|
||||
INNER JOIN bibliografia_sito bs ON bs.id_bibliografia = b.id
|
||||
WHERE bs.id_sito = :siteId
|
||||
ORDER BY bs.ordine ASC
|
||||
';
|
||||
|
||||
$query->setParameter('id', $siteId);
|
||||
$stmt = $conn->prepare($sql);
|
||||
$results = $stmt->executeQuery(['siteId' => $siteId])->fetchAllAssociative();
|
||||
|
||||
return $query->getResult();
|
||||
$entities = [];
|
||||
|
||||
foreach ($results as $row) {
|
||||
$biblio = new Bibliography();
|
||||
$biblio->setId($row['id']);
|
||||
$biblio->setCitation($row['citazione']);
|
||||
$biblio->setReference($row['riferimento']);
|
||||
$biblio->setPages($row['pagine']);
|
||||
$entities[] = $biblio;
|
||||
}
|
||||
|
||||
return $entities;
|
||||
}
|
||||
/**
|
||||
* @return Bibliography[]
|
||||
|
@ -22,28 +22,40 @@ class DocumentRepository extends ServiceEntityRepository
|
||||
*/
|
||||
public function findBySite(int $siteId): array
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Document', 'd');
|
||||
$query = $this->getEntityManager()->createNativeQuery(
|
||||
'SELECT
|
||||
id,
|
||||
titolo,
|
||||
filename,
|
||||
descrizione,
|
||||
autori,
|
||||
luogo,
|
||||
tipo
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
$sql = '
|
||||
SELECT
|
||||
d.id,
|
||||
d.titolo,
|
||||
d.filename,
|
||||
d.descrizione,
|
||||
d.autori,
|
||||
d.tipo,
|
||||
d.luogo
|
||||
FROM documento d
|
||||
JOIN sito_documento
|
||||
ON id_documento = d.id
|
||||
WHERE id_sito = :id
|
||||
',
|
||||
$rsm
|
||||
);
|
||||
INNER JOIN sito_documento sd ON sd.id_documento = d.id
|
||||
WHERE sd.id_sito = :siteId
|
||||
';
|
||||
|
||||
$query->setParameter('id', $siteId);
|
||||
$stmt = $conn->prepare($sql);
|
||||
$results = $stmt->executeQuery(['siteId' => $siteId])->fetchAllAssociative();
|
||||
|
||||
return $query->getResult();
|
||||
$entities = [];
|
||||
|
||||
foreach ($results as $row) {
|
||||
$document = new Document();
|
||||
$document->setId($row['id']);
|
||||
$document->setTitle($row['titolo']);
|
||||
$document->setFilename($row['filename']);
|
||||
$document->setDescription($row['descrizione']);
|
||||
$document->setConservationPlace($row['luogo']);
|
||||
$document->setType($row['tipo']);
|
||||
$document->setAuthors($row['autori']);
|
||||
$entities[] = $document;
|
||||
}
|
||||
|
||||
return $entities;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user