Skip to content

Commit

Permalink
[10.x] Fix whenAggregated when default is not specified (#49521)
Browse files Browse the repository at this point in the history
* Fix: whenAggregated should return MissingValue when default is not specified

* Test: whenAggregated should return MissingValue when default is not specified
  • Loading branch information
lovePizza authored Jan 1, 2024
1 parent a5f661f commit f8c6360
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ public function whenCounted($relationship, $value = null, $default = null)
*/
public function whenAggregated($relationship, $column, $aggregate, $value = null, $default = null)
{
if (func_num_args() < 5) {
$default = new MissingValue;
}

$attribute = (string) Str::of($relationship)->snake()->append('_')->append($aggregate)->append('_')->finish($column);

if (! isset($this->resource->getAttributes()[$attribute])) {
Expand Down
2 changes: 0 additions & 2 deletions tests/Integration/Http/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,6 @@ public function testResourcesMayHaveOptionalRelationshipAggregates()
'data' => [
'id' => 5,
'title' => 'Test Title',
'average_rating' => null,
'minimum_rating' => null,
'maximum_rating' => 'Default Value',
],
]);
Expand Down

0 comments on commit f8c6360

Please sign in to comment.