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')]
public function notificationDm(Request $request, MerServiceRepository $repo): Response
{
foreach ($repo->findByOfferId($request->query->get('offer_id')) as $sub) {
dump($sub);
}
dump('MerServiceRepository->findByOfferId');
dump($repo->findByOfferId($request->query->get('offer_id')));
return $this->render('index/notificationDm.html.twig');
}

View File

@ -4,6 +4,8 @@ namespace App\Repository;
use App\Entity\MerService;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Persistence\ManagerRegistry;
/**
@ -65,11 +67,29 @@ class MerServiceRepository extends ServiceEntityRepository
public function findByOfferId(int $offerId)
{
return $this->createQueryBuilder('s')
->andWhere('s.offer_id = :offer_id')
->setParameter('offer_id', $offerId)
->getQuery()
->getResult()
;
// return $this->createQueryBuilder('s')
// ->andWhere('s.offer_id = :offer_id')
// ->setParameter('offer_id', $offerId)
// ->getQuery()
// ->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;
}
}