Refactored TagInfo to wrap the raw tag name instead of a Tag entity

This commit is contained in:
Alejandro Celaya
2022-01-23 09:37:02 +01:00
parent dd6bcd68cc
commit 8adb6596fb
9 changed files with 14 additions and 18 deletions

View File

@@ -108,13 +108,13 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
$nativeQb->addOrderBy('t.name_1', $orderMainQuery || $orderDir === null ? 'ASC' : $orderDir);
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata(Tag::class, 't');
$rsm->addScalarResult('name', 'tag');
$rsm->addScalarResult('short_urls_count', 'shortUrlsCount');
$rsm->addScalarResult('visits_count', 'visitsCount');
return map(
$this->getEntityManager()->createNativeQuery($nativeQb->getSQL(), $rsm)->getResult(),
static fn (array $row) => new TagInfo($row[0], (int) $row['shortUrlsCount'], (int) $row['visitsCount']),
static fn (array $row) => new TagInfo($row['tag'], (int) $row['shortUrlsCount'], (int) $row['visitsCount']),
);
}