Skip to content

Commit 2f976cd

Browse files
axelitusAlexVanderbist
authored andcommitted
Set columnName to the processed property value (#180)
* Add test for descending default sort
1 parent d5b322a commit 2f976cd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Sort.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(string $property, $sortClass, ?string $columnName =
2929

3030
$this->defaultDirection = static::parsePropertyDirection($property);
3131

32-
$this->columnName = $columnName ?? $property;
32+
$this->columnName = $columnName ?? $this->property;
3333
}
3434

3535
public static function parsePropertyDirection(string $property): string

tests/SortTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ public function it_uses_default_sort_parameter()
120120
$this->assertSortedAscending($sortedModels, 'name');
121121
}
122122

123+
/** @test */
124+
public function it_uses_default_descending_sort_parameter()
125+
{
126+
$sortedModels = QueryBuilder::for(TestModel::class, new Request())
127+
->allowedSorts('-name')
128+
->defaultSort('-name')
129+
->get();
130+
131+
$this->assertQueryExecuted('select * from "test_models" order by "name" desc');
132+
$this->assertSortedDescending($sortedModels, 'name');
133+
}
134+
123135
/** @test */
124136
public function it_can_allow_multiple_sort_parameters()
125137
{

0 commit comments

Comments
 (0)