extends |
Model |
|---|
AggregateModel model allows you to query using "group by" clause on your existing model. It's quite simple to set up.
$aggregate = new AggregateModel($mymodel); $aggregate->setGroupBy(['first', 'last'], [ 'salary' => ['expr' => 'sum([])', 'type' => 'atk4_money'], ];
your resulting model will have 3 fields: first, last, salary
but when querying it will use the original model to calculate the query, then add grouping and aggregates.
If you wish you can add more fields, which will be passed through: $aggregate->addField('middle');
If this field exist in the original model it will be added and you'll get exception otherwise. Finally you are permitted to add expressions.
| Methods | ||
|---|---|---|
public
|
__construct(Model $baseModel, array<string, mixed> $defaults = [])
|
# |
public
|
setGroupBy(array<int, string|Expression> $fields, array<string, array<mixed>|object> $aggregateExpressions = []): $this
|
# |
public
|
addField(string $name, $seed = []): Field
|
# |
public
|
action(string $mode, array $args = [])
|
# |
protected
|
initQueryGrouping(Query $query): void
|
# |
public
|
__debugInfo(): array
|
# |
public
|
getPersistence(): Sql
|
# |
public
|
expr(string $template, array<int|string, mixed> $arguments = []): Expression
|
# |
| Methods used from Atk4\Core\CollectionTrait |
|---|
_removeFromCollection(), _cloneCollection(), _hasInCollection(), _getFromCollection(), _shortenMl() |
| Methods used from Atk4\Core\ContainerTrait |
|---|
_uniqueElementName(), _addContainer(), removeElement(), _shorten(), getElement(), hasElement() |
| Methods used from Atk4\Core\DiContainerTrait |
|---|
setDefaults(), setMissingProperty(), assertInstanceOf(), _fromSeedPrecheck(), fromSeed(), fromSeedUnsafe() |
| Methods used from Atk4\Core\DynamicMethodTrait |
|---|
__call(), buildMethodHookName(), addMethod(), hasMethod(), removeMethod() |
| Methods used from Atk4\Core\InitializerTrait |
|---|
isInitialized(), invokeInit() |
| Methods used from Atk4\Data\Model\JoinsTrait |
|---|
join(), leftJoin(), hasJoin(), getJoin(), getJoins() |
| Methods used from Atk4\Core\ReadableCaptionTrait |
|---|
readableCaption() |
| Constants | ||
|---|---|---|
public
|
HOOK_INIT_AGGREGATE_SELECT_QUERY = self::class . '@initAggregateSelectQuery'
|
# |
| Properties | |||
|---|---|---|---|
public
|
array<int, string|Expression>
|
$groupByFields = []
|
# |
public
|
Model
|
$table
|
# |
| Properties used from Atk4\Core\ContainerTrait |
|---|
$_elementNameCounts |
| Properties used from Atk4\Core\HookTrait |
|---|
$hooks, $_hookIndexCounter, $_hookOrigThis |
| Properties used from Atk4\Core\InitializerTrait |
|---|
$_initialized |
| Properties used from Atk4\Data\Model\JoinsTrait |
|---|
$_defaultSeedJoin |
| Properties used from Atk4\Data\Model\ReferencesTrait |
|---|
$_defaultSeedAddReference, $_defaultSeedHasOne, $_defaultSeedHasMany, $_defaultSeedContainsOne, $_defaultSeedContainsMany |
| Properties used from Atk4\Data\Model\UserActionsTrait |
|---|
$_defaultSeedUserAction, $userActions |