Skip to content

Commit

Permalink
Fix issue with sprunje using multiple listable fetched from database
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Apr 20, 2024
1 parent 373f9b2 commit 17c6832
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [5.1.1](https://github.com/userfrosting/sprinkle-core/compare/5.1.0...5.1.1)
- Fix issue with sprunje using multiple listable fetched from database ([Chat Reference](https://chat.userfrosting.com/channel/support?msg=sgMq8sbAjsCN2ZGXj))

## [5.1.0](https://github.com/userfrosting/sprinkle-core/compare/5.0.1...5.1.0)
- Drop PHP 8.1 support, add PHP 8.3 support
- Update to Laravel 10
Expand Down
5 changes: 4 additions & 1 deletion app/src/Sprunje/Sprunje.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,11 @@ abstract protected function baseQuery();
*/
protected function getColumnValues(string $column): array
{
// Clone query, so we don't modify the initial one
$query = clone $this->query;

/** @var Collection<int, mixed[]> */
$rawValues = $this->query->select($column)
$rawValues = $query->select($column)
->distinct()
->orderBy($column, 'asc')
->get();
Expand Down
21 changes: 14 additions & 7 deletions app/tests/Integration/Sprunje/SprunjeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ class SprunjeTest extends CoreTestCase
{
/** @var mixed[] */
protected array $listable = [
'type' => [
['value' => 1, 'text' => 'TYPE A'],
['value' => 2, 'text' => 'TYPE B'],
],
'name' => [
// N.B.: Values are sorted automatically
['value' => 'bar', 'text' => 'bar'],
['value' => 'foo', 'text' => 'foo'],
['value' => 'foobar', 'text' => 'foobar'],
],
'type' => [
['value' => 1, 'text' => 'TYPE A'],
['value' => 2, 'text' => 'TYPE B'],
],
'active' => [
['value' => false, 'text' => false],
['value' => true, 'text' => true],
]
];

public function setUp(): void
Expand Down Expand Up @@ -203,11 +207,11 @@ public function testWithCustomSort(): void
public function testWithSortException(): void
{
$sprunje = new TestSprunje([
'sorts' => ['description' => 'desc'],
'sorts' => ['active' => 'desc'],
]);

$this->expectException(SprunjeException::class);
$this->expectExceptionMessage('Bad sort: description');
$this->expectExceptionMessage('Bad sort: active');
$sprunje->getArray();
}

Expand Down Expand Up @@ -491,11 +495,14 @@ class TestSprunje extends Sprunje
protected array $sortable = [
'id',
'name',
'description',
'type',
];

protected array $listable = [
'name',
'type',
'name',
'active',
];

protected function baseQuery()
Expand Down

0 comments on commit 17c6832

Please sign in to comment.