nova-issues icon indicating copy to clipboard operation
nova-issues copied to clipboard

Partition Metrics - Access nested JSON Field

Open bkhkcm opened this issue 1 year ago • 1 comments

  • Laravel Version: ^10.0
  • Nova Version: 4.26.5
  • PHP Version: 8.2.4
  • Database Driver & Version: pdo_mysql, mysqlnd 8.2.4

Description:

In my partition metric I want to access a nested JSON field.

public function calculate(NovaRequest $request) {
  return $this->count($request, User::class, 'meta->notifications->newsletters');
}

However, I don't get any correct data back.

Screenshot 2024-08-13 at 13 55 50

If I make a query directly to the database:

SELECT JSON_UNQUOTE(JSON_EXTRACT(meta, '$.notifications.newsletters')) AS opt, COUNT(*) as aggregate FROM users GROUP BY opt;

Do I get the following data:

opt aggregate
true 58
false 13
NULL 1

bkhkcm avatar Aug 13 '24 12:08 bkhkcm

It seems that in the file /vendor/laravel/nova/src/Metrics/Partition.php, when calling the function formatAggregateResult, an empty string is passed for $key.

bkhkcm avatar Aug 13 '24 13:08 bkhkcm

Released with Laravel Nova 5.0.0

Feel free to open up a new issue if you're still experiencing this problem on the latest version.

crynobone avatar Dec 16 '24 04:12 crynobone

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 22 '24 00:12 github-actions[bot]