Skip to content

Commit 95be4be

Browse files
committed
Select: Added two methods getOrderBy and resetOrderBy
1 parent af5b285 commit 95be4be

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/Builder/Traits/OrderByBuilder.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ public function orderByValues(string $fieldName, array $values) {
3939
return $this;
4040
}
4141

42+
/**
43+
* @param string $fieldName
44+
* @param array<int, int|float|string> $values
45+
* @return
46+
*/
47+
public function getOrderBy() {
48+
return $this->orderBy;
49+
}
50+
51+
/**
52+
* Removed all order information from the current layer. This dies not affect sub-selects.
53+
*
54+
* @return $this
55+
*/
56+
public function resetOrderBy() {
57+
$this->orderBy = [];
58+
return $this;
59+
}
60+
4261
/**
4362
* @param string $query
4463
* @return string

tests/Builder/SelectTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,16 @@ public function testDBExprFilter(): void {
222222
}
223223

224224
public function testOrder(): void {
225-
$str = $this->select()
225+
$select = $this->select()
226226
->field('a')
227227
->from('t', 'test')
228-
->orderBy('a', 'DESC')
229-
->asString();
228+
->orderBy('a', 'DESC');
229+
$str = $select->asString();
230230
self::assertEquals("SELECT\n\ta\nFROM\n\ttest t\nORDER BY\n\ta DESC\n", $str);
231+
self::assertEquals([['a', 'DESC']], $select->getOrderBy());
232+
$select->resetOrderBy();
233+
self::assertEquals("SELECT\n\ta\nFROM\n\ttest t\n", $str);
234+
self::assertEquals([], $select->getOrderBy());
231235
}
232236

233237
public function testGroup(): void {

0 commit comments

Comments
 (0)