Skip to content

Commit

Permalink
JSON field bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
robinsonjohn committed Oct 8, 2024
1 parent 218690b commit dcf074c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/query-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ This example represents a column named `supplier` with type of `json`.
<hr />

Select up to 10 results for `name`, `color`, `quantity` from `items` table where `description` contains the word "fluffy", and the price is less than `50.00`, ordered by `name` descending.
Also, get the total number of rows found for the query without limit restrictions.
Also, get the total number of rows found for the query.

```php
use Bayfront\SimplePdo\Query;
Expand All @@ -503,7 +503,7 @@ $results = $query->table('items')
->limit(10)
->get();

$total_count = $query->getTotalRows();
$total_count = $query->aggregate($query::AGGREGATE_COUNT);
```

<hr />
Expand All @@ -530,5 +530,5 @@ $results = $query->table('items')
->limit(10)
->get();

$total_count = $query->getTotalRows();
$total_count = $query->aggregate($query::AGGREGATE_COUNT);
```
6 changes: 6 additions & 0 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,12 @@ private function formatResult(array $result): array
$arr = explode("->>'$.", rtrim($k, "'"), 2);
$col = $arr[0];

$col_exp = explode('.', $col, 2);

if (isset($col_exp[1])) {
$col = $col_exp[1];
}

Arr::set($result, $col . '.' . $arr[1], $v);
unset($result[$k]);

Expand Down

0 comments on commit dcf074c

Please sign in to comment.