mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Ensure single result when retrieving activity and event linked to stored object
Although a many-to-many relationship exists between these entities and stored object, only one activity or event will ever be linked to a single stored object. For extra safety measure we return a single result in the repository to ensure our voters will keep working.
This commit is contained in:
parent
c06e76a0ee
commit
a25f2c7539
@ -17,6 +17,8 @@ use Chill\DocStoreBundle\Repository\AssociatedEntityToStoredObjectInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@ -100,6 +102,10 @@ class ActivityRepository extends ServiceEntityRepository implements AssociatedEn
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
*/
|
||||
public function findAssociatedEntityToStoredObject(StoredObject $storedObject): ?object
|
||||
{
|
||||
$qb = $this->createQueryBuilder('a');
|
||||
@ -110,6 +116,6 @@ class ActivityRepository extends ServiceEntityRepository implements AssociatedEn
|
||||
->setParameter('storedObjectId', $storedObject->getId())
|
||||
->getQuery();
|
||||
|
||||
return $query->getResult();
|
||||
return $query->getSingleResult();
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ use Chill\DocStoreBundle\Repository\AssociatedEntityToStoredObjectInterface;
|
||||
use Chill\EventBundle\Entity\Event;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
@ -36,6 +38,10 @@ class EventRepository implements ObjectRepository, AssociatedEntityToStoredObjec
|
||||
return $this->repository->createQueryBuilder($alias, $indexBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
*/
|
||||
public function findAssociatedEntityToStoredObject(StoredObject $storedObject): ?object
|
||||
{
|
||||
$qb = $this->createQueryBuilder('e');
|
||||
@ -46,7 +52,7 @@ class EventRepository implements ObjectRepository, AssociatedEntityToStoredObjec
|
||||
->setParameter('storedObjectId', $storedObject->getId())
|
||||
->getQuery();
|
||||
|
||||
return $query->getResult();
|
||||
return $query->getSingleResult();
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user