root query

This commit is contained in:
Sergio Álvarez 2022-05-24 09:14:42 +02:00
parent b58b92bc30
commit b1d6490d24
No known key found for this signature in database
GPG Key ID: 622780889DFDBDA5
2 changed files with 28 additions and 9 deletions

View File

@ -42,9 +42,8 @@ class IndexController extends AbstractController
#[Route('/notification/dm', name: 'notification_dm')] #[Route('/notification/dm', name: 'notification_dm')]
public function notificationDm(Request $request, MerServiceRepository $repo): Response public function notificationDm(Request $request, MerServiceRepository $repo): Response
{ {
foreach ($repo->findByOfferId($request->query->get('offer_id')) as $sub) { dump('MerServiceRepository->findByOfferId');
dump($sub); dump($repo->findByOfferId($request->query->get('offer_id')));
}
return $this->render('index/notificationDm.html.twig'); return $this->render('index/notificationDm.html.twig');
} }

View File

@ -4,6 +4,8 @@ namespace App\Repository;
use App\Entity\MerService; use App\Entity\MerService;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
/** /**
@ -65,11 +67,29 @@ class MerServiceRepository extends ServiceEntityRepository
public function findByOfferId(int $offerId) public function findByOfferId(int $offerId)
{ {
return $this->createQueryBuilder('s') // return $this->createQueryBuilder('s')
->andWhere('s.offer_id = :offer_id') // ->andWhere('s.offer_id = :offer_id')
->setParameter('offer_id', $offerId) // ->setParameter('offer_id', $offerId)
->getQuery() // ->getQuery()
->getResult() // ->getResult()
; // ;
$rsm = new ResultSetMapping();
$rsm->addEntityResult($this->getClassName(), 's');
$rsm->addFieldResult('s', 'id', 'id');
$rsm->addMetaResult('s', 'discr', 'discr');
$rsm->setDiscriminatorColumn('s', 'discr');
$query = $this->getEntityManager()
->createNativeQuery('SELECT * FROM mer_service m WHERE offer_id = :offer_id', $rsm);
$query->setParameter('offer_id', $offerId);
$res = $query->getResult();
foreach ($res as $k => $obj) {
$this->getEntityManager()->refresh($obj);
}
return $res;
} }
} }