Skip to content

Commit

Permalink
Merge branch '7.0.2-erasys' into upgradeToPhp82
Browse files Browse the repository at this point in the history
  • Loading branch information
datcal authored Jul 26, 2023
2 parents 8160ecb + 903660e commit 7106a42
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
13 changes: 12 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
"role": "Developer"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/erasys/eloquence-base"
},
{
"type": "vcs",
"url": "https://github.com/erasys/hookable"
}
],
"require": {
"php": ">=8.2",
"sofa/eloquence-base": "8.0.0"
Expand All @@ -52,7 +62,8 @@
"Sofa\\Eloquence\\Tests\\": "tests"
}
},
"minimum-stability": "stable",
"minimum-stability": "dev",
"prefer_stable": true,
"scripts": {
"test": "./vendor/bin/phpunit && ./vendor/bin/phpcs src --standard=psr2 --report=diff --colors",
"phpcs": "./vendor/bin/phpcs src --standard=psr2 --report=diff --colors"
Expand Down
23 changes: 23 additions & 0 deletions src/Mappable.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ protected function mappedQuery(Builder $query, $method, ArgumentBag $args) : mix
return $query->callParent($method, $args->all());
}

/**
* Custom group by to group by mapped attributes
*
* @param \Sofa\Eloquence\Builder $query
* @param \Sofa\Hookable\Contracts\ArgumentBag $args
* @return void
*/
protected function mappedGroupBy(Builder $query, ArgumentBag $args)
{
$groupArgs = $args->get('groups');
$groups = \is_array($groupArgs[0]) ? $groupArgs[0] : $groupArgs;

foreach ($groups as $key => $group) {
if ($this->hasMapping($group)) {
$mapping = $this->getMappingForAttribute($group);

$groups[$key] = $mapping;
}
}

$args->set('groups', $groups);
}

/**
* Adjust mapped columns for select statement.
*
Expand Down
4 changes: 4 additions & 0 deletions src/Mappable/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function queryHook()
call_user_func_array([$this, 'mappedSelect'], [$query, $args]);
}

if ($method === 'groupBy') {
call_user_func_array([$this, 'mappedGroupBy'], [$query, $args]);
}

return $next($query, $bag);
};
}
Expand Down

0 comments on commit 7106a42

Please sign in to comment.