mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-27 20:11:34 +03:00
Fixed entity mapping for visits without a visit location
This commit is contained in:
parent
867659ea25
commit
d5288f756e
1 changed files with 4 additions and 5 deletions
|
@ -104,8 +104,7 @@ class VisitRepository extends EntityRepository implements VisitRepositoryInterfa
|
||||||
// FIXME Crappy way to resolve the params into the query. Best option would be to inject the sub-query with
|
// FIXME Crappy way to resolve the params into the query. Best option would be to inject the sub-query with
|
||||||
// placeholders and then pass params to the main query
|
// placeholders and then pass params to the main query
|
||||||
$shortUrlId = $shortUrl instanceof ShortUrl ? $shortUrl->getId() : $shortUrl;
|
$shortUrlId = $shortUrl instanceof ShortUrl ? $shortUrl->getId() : $shortUrl;
|
||||||
$subQuery = $qb->getQuery()->getSQL();
|
$subQuery = preg_replace('/\?/', $shortUrlId, $qb->getQuery()->getSQL(), 1);
|
||||||
$subQuery = preg_replace('/\?/', $shortUrlId, $subQuery, 1);
|
|
||||||
if ($dateRange !== null && $dateRange->getStartDate() !== null) {
|
if ($dateRange !== null && $dateRange->getStartDate() !== null) {
|
||||||
$subQuery = preg_replace(
|
$subQuery = preg_replace(
|
||||||
'/\?/',
|
'/\?/',
|
||||||
|
@ -120,16 +119,16 @@ class VisitRepository extends EntityRepository implements VisitRepositoryInterfa
|
||||||
|
|
||||||
// A native query builder needs to be used here because DQL and ORM query builders do not accept
|
// A native query builder needs to be used here because DQL and ORM query builders do not accept
|
||||||
// sub-queries at "from" and "join" level.
|
// sub-queries at "from" and "join" level.
|
||||||
// If no sub-query is used, then the performance drops dramatically while the "offset" grows.
|
// If no sub-query is used, then performance drops dramatically while the "offset" grows.
|
||||||
$nativeQb = $this->getEntityManager()->getConnection()->createQueryBuilder();
|
$nativeQb = $this->getEntityManager()->getConnection()->createQueryBuilder();
|
||||||
$nativeQb->select('v.*', 'vl.*')
|
$nativeQb->select('v.id AS visit_id', 'v.*', 'vl.*')
|
||||||
->from('visits', 'v')
|
->from('visits', 'v')
|
||||||
->join('v', '(' . $subQuery . ')', 'sq', $nativeQb->expr()->eq('sq.id_0', 'v.id'))
|
->join('v', '(' . $subQuery . ')', 'sq', $nativeQb->expr()->eq('sq.id_0', 'v.id'))
|
||||||
->leftJoin('v', 'visit_locations', 'vl', $nativeQb->expr()->eq('v.visit_location_id', 'vl.id'))
|
->leftJoin('v', 'visit_locations', 'vl', $nativeQb->expr()->eq('v.visit_location_id', 'vl.id'))
|
||||||
->orderBy('v.id', 'DESC');
|
->orderBy('v.id', 'DESC');
|
||||||
|
|
||||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||||
$rsm->addRootEntityFromClassMetadata(Visit::class, 'v');
|
$rsm->addRootEntityFromClassMetadata(Visit::class, 'v', ['id' => 'visit_id']);
|
||||||
$rsm->addJoinedEntityFromClassMetadata(VisitLocation::class, 'vl', 'v', 'visitLocation', [
|
$rsm->addJoinedEntityFromClassMetadata(VisitLocation::class, 'vl', 'v', 'visitLocation', [
|
||||||
'id' => 'visit_location_id',
|
'id' => 'visit_location_id',
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue