orm groupBy => group

This commit is contained in:
Yuri Kuznetsov
2021-07-26 13:40:17 +03:00
parent 57bb2a3978
commit 04203312bf
19 changed files with 76 additions and 36 deletions

View File

@@ -65,7 +65,7 @@ class TemplateEntityTypeList
->withAccessControlFilter()
->buildQueryBuilder()
->select(['entityType'])
->groupBy(['entityType'])
->group(['entityType'])
->build();
$templateCollection = $this->entityManager

View File

@@ -136,7 +136,7 @@ class SumRelatedType extends \Espo\Core\Formula\Functions\Base implements
]);
}
$queryBuilder->groupBy($foreignLinkAlias . '.id');
$queryBuilder->group($foreignLinkAlias . '.id');
$sth = $entityManager->getQueryExecutor()->execute($queryBuilder->build());

View File

@@ -81,7 +81,7 @@ abstract class AbstractGroupJob implements JobPreparable
'group!=' => null,
'executeTime<=' => $executeTime->format(DateTime::SYSTEM_DATE_TIME_FORMAT),
])
->groupBy('group')
->group('group')
->build();
$sth = $this->entityManager->getQueryExecutor()->execute($query);

View File

@@ -390,7 +390,7 @@ class QueueUtil
'scheduledJob.job!=' => $this->metadataProvider->getPreparableJobNameList(),
'targetId' => null,
])
->groupBy(['scheduledJobId'])
->group(['scheduledJobId'])
->having([
'COUNT:id>' => 1,
])

View File

@@ -109,7 +109,7 @@ class Manager
$list = $this->entityManager
->getRDBRepository(Webhook::ENTITY_TYPE)
->select(['event'])
->groupBy(['event'])
->group(['event'])
->where([
'isActive' => true,
'event!=' => null,

View File

@@ -167,7 +167,7 @@ class Queue
['processAt<=' => DateTimeUtil::getSystemNowString()],
],
])
->groupBy('webhookId')
->group('webhookId')
->build()
)
)

View File

@@ -220,7 +220,7 @@ class StatsLoader implements Loader
'stage' => 'Closed Won',
'campaignId' => $entity->getId(),
])
->groupBy('opportunity.campaignId')
->group('opportunity.campaignId')
->build();
$sth = $this->entityManager->getQueryExecutor()->execute($query);

View File

@@ -110,7 +110,7 @@ class Opportunity extends Record
['SUM:amountConverted', 'amount'],
])
->order('LIST:'.$stageField.':' . implode(',', $options))
->groupBy($stageField)
->group($stageField)
->where($whereClause);
if ($teamId) {
@@ -200,7 +200,7 @@ class Opportunity extends Record
['SUM:amountWeightedConverted', 'amount'],
])
->order('LIST:leadSource:' . implode(',', $options))
->groupBy('leadSource')
->group('leadSource')
->where($whereClause);
$this->handleDistinctReportQueryBuilder($queryBuilder, $whereClause);
@@ -260,7 +260,7 @@ class Opportunity extends Record
['SUM:amountConverted', 'amount'],
])
->order('LIST:stage:' . implode(',', $options))
->groupBy('stage')
->group('stage')
->where($whereClause);
$stageIgnoreList = array_merge($this->getLostStageList(), $this->getWonStageList());
@@ -337,7 +337,7 @@ class Opportunity extends Record
['SUM:amountConverted', 'amount'],
])
->order('MONTH:closeDate')
->groupBy('MONTH:closeDate')
->group('MONTH:closeDate')
->where($whereClause);
$this->handleDistinctReportQueryBuilder($queryBuilder, $whereClause);

View File

@@ -126,7 +126,7 @@ class TargetList extends \Espo\Services\Record implements
'action=' => $includingActionList,
]);
$queryBuilder->groupBy([
$queryBuilder->group([
'parentId',
'parentType',
'id',

View File

@@ -153,7 +153,7 @@ class Select implements SelectingQuery
*
* @return Expression[]
*/
public function getGroupBy(): array
public function getGroup(): array
{
return array_map(
function (string $item) {

View File

@@ -178,7 +178,7 @@ class SelectBuilder implements Builder
*
* @param Expression|Expression[]|string|string[] $groupBy
*/
public function groupBy($groupBy): self
public function group($groupBy): self
{
if (is_array($groupBy)) {
$this->params['groupBy'] = $this->normilizeExpressionItemArray($groupBy);
@@ -201,6 +201,14 @@ class SelectBuilder implements Builder
throw new InvalidArgumentException();
}
/**
* @deprecated Use `group` method.
*/
public function groupBy($groupBy): self
{
return $this->group($groupBy);
}
/**
* Use index.
*/

View File

@@ -314,9 +314,17 @@ class RDBRelation
*
* @param Expression|Expression[]|string|string[] $groupBy
*/
public function group($groupBy): Builder
{
return $this->createSelectBuilder()->group($groupBy);
}
/**
* @deprecated Use `group` method.
*/
public function groupBy($groupBy): Builder
{
return $this->createSelectBuilder()->groupBy($groupBy);
return $this->group($groupBy);
}
/**

View File

@@ -397,13 +397,21 @@ class RDBRelationSelectBuilder
*
* @param Expression|Expression[]|string|string[] $groupBy
*/
public function groupBy($groupBy): self
public function group($groupBy): self
{
$this->builder->groupBy($groupBy);
$this->builder->group($groupBy);
return $this;
}
/**
* @deprecated Use `group` method.
*/
public function groupBy($groupBy): self
{
return $this->group($groupBy);
}
protected function getMiddleTableAlias(): ?string
{
if (!$this->isManyMany()) {

View File

@@ -810,9 +810,17 @@ class RDBRepository extends Repository
*
* @param Expression|Expression[]|string|string[] $groupBy
*/
public function group($groupBy): RDBSelectBuilder
{
return $this->createSelectBuilder()->group($groupBy);
}
/**
* @deprecated Use `group` method.
*/
public function groupBy($groupBy): RDBSelectBuilder
{
return $this->createSelectBuilder()->groupBy($groupBy);
return $this->group($groupBy);
}
/**

View File

@@ -336,13 +336,21 @@ class RDBSelectBuilder
*
* @param Expression|Expression[]|string|string[] $groupBy
*/
public function groupBy($groupBy): self
public function group($groupBy): self
{
$this->builder->groupBy($groupBy);
$this->builder->group($groupBy);
return $this;
}
/**
* @deprecated Use `group` method.
*/
public function groupBy($groupBy): self
{
return $this->group($groupBy);
}
protected function handleReturnCollection(SthCollection $collection): Collection
{
if ($this->returnSthCollection) {

View File

@@ -94,7 +94,7 @@ class LastViewed
'MAX:number',
['MAX:createdAt', 'createdAt'],
])
->groupBy(['targetId', 'targetType'])
->group(['targetId', 'targetType'])
->limit($offset, $params['maxSize'] + 1)
->find();

View File

@@ -1047,7 +1047,7 @@ class MysqlQueryComposerTest extends \PHPUnit\Framework\TestCase
->leftJoin('post')
->distinct()
->order('LIST:post.name:Test,Hello')
->groupBy('post.name')
->group('post.name')
->build();
$sql = $this->query->compose($select);
@@ -2388,7 +2388,7 @@ class MysqlQueryComposerTest extends \PHPUnit\Framework\TestCase
'a.name' => 'Test',
])
->order('a.name')
->groupBy(['id'])
->group(['id'])
->withDeleted()
->build();

View File

@@ -230,7 +230,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase
$select = $this->builder
->from('Test')
->having(['test' => null])
->groupBy(['test'])
->group(['test'])
->build();
$raw = $select->getRaw();
@@ -245,7 +245,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase
$select = $this->builder
->from('Test')
->having(Cond::equal(Expr::column('test'), null))
->groupBy(Expr::create('test'))
->group(Expr::create('test'))
->build();
$raw = $select->getRaw();
@@ -257,7 +257,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase
{
$select = $this->builder
->from('Test')
->groupBy([
->group([
Expr::create('test1'),
Expr::create('test2'),
])
@@ -269,7 +269,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase
Expr::create('test1'),
Expr::create('test2'),
],
$select->getGroupBy()
$select->getGroup()
);
}
@@ -278,7 +278,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase
$select = $this->builder
->from('Test')
->having(Cond::equal(Expr::column('test'), null))
->groupBy(Expr::create('test'))
->group(Expr::create('test'))
->build();

View File

@@ -744,7 +744,7 @@ class RDBRepositoryTest extends \PHPUnit\Framework\TestCase
->will($this->returnValue($this->collection))
->with($paramsExpected);
$this->repository->groupBy('id')->find();
$this->repository->group('id')->find();
}
public function testGroupBy2()
@@ -761,8 +761,8 @@ class RDBRepositoryTest extends \PHPUnit\Framework\TestCase
->with($paramsExpected);
$this->repository
->groupBy('id')
->groupBy('name')
->group('id')
->group('name')
->find();
}
@@ -780,8 +780,8 @@ class RDBRepositoryTest extends \PHPUnit\Framework\TestCase
->with($paramsExpected);
$this->repository
->groupBy('id')
->groupBy(['id', 'name'])
->group('id')
->group(['id', 'name'])
->find();
}
@@ -799,8 +799,8 @@ class RDBRepositoryTest extends \PHPUnit\Framework\TestCase
->with($paramsExpected);
$this->repository
->groupBy(Expr::create('id'))
->groupBy(Expr::create('name'))
->group(Expr::create('id'))
->group(Expr::create('name'))
->find();
}
@@ -818,7 +818,7 @@ class RDBRepositoryTest extends \PHPUnit\Framework\TestCase
->with($paramsExpected);
$this->repository
->groupBy([Expr::create('id'), Expr::create('name')])
->group([Expr::create('id'), Expr::create('name')])
->find();
}