From 00bf552ff9d2a9b368ac48fe9cf59ae087f91634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hrani=C4=8Dka?= Date: Wed, 25 Feb 2015 15:45:39 +0100 Subject: [PATCH 1/2] Tests: Test Selection for order direction --- tests/Database/Table/Selection.order().phpt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Database/Table/Selection.order().phpt b/tests/Database/Table/Selection.order().phpt index 58cffd1bd..05265e9ec 100644 --- a/tests/Database/Table/Selection.order().phpt +++ b/tests/Database/Table/Selection.order().phpt @@ -14,12 +14,14 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { $apps = array(); - foreach ($context->table('book')->where('title LIKE ?', '%t%')->order('title')->limit(3) as $book) { // SELECT * FROM `book` WHERE (`title` LIKE ?) ORDER BY `title` LIMIT 3 + + $selection = $context->table('book')->where('title LIKE ?', '%t%')->order('title DESC')->limit(3); + foreach ($selection as $book) { // SELECT * FROM `book` WHERE (`title` LIKE ?) ORDER BY `title` DESC LIMIT 3 $apps[] = $book->title; } Assert::same(array( - '1001 tipu a triku pro PHP', 'Nette', + '1001 tipu a triku pro PHP', ), $apps); }); From 90ce2f8e0f59e65fda1d046559285061086bc856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hrani=C4=8Dka?= Date: Wed, 25 Feb 2015 15:46:46 +0100 Subject: [PATCH 2/2] Selection::resetOrder added --- src/Database/Table/Selection.php | 12 ++++++++++++ tests/Database/Table/Selection.order().phpt | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 1eda82fa5..502cb2558 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -349,6 +349,18 @@ public function order($columns) } + /** + * Resets current order clause. + * @return self + */ + public function resetOrder() + { + $this->emptyResultSet(); + $this->sqlBuilder->setOrder(array(), array()); + return $this; + } + + /** * Sets limit clause, more calls rewrite old values. * @param int diff --git a/tests/Database/Table/Selection.order().phpt b/tests/Database/Table/Selection.order().phpt index 05265e9ec..c0707a1b8 100644 --- a/tests/Database/Table/Selection.order().phpt +++ b/tests/Database/Table/Selection.order().phpt @@ -25,3 +25,18 @@ test(function() use ($context) { '1001 tipu a triku pro PHP', ), $apps); }); + +test(function() use ($context) { + $apps = array(); + + $selection = $context->table('book')->order('title DESC')->resetOrder()->limit(3); + foreach ($selection as $book) { // SELECT * FROM `book` LIMIT 3 + $apps[] = $book->title; + } + + Assert::same(array( + '1001 tipu a triku pro PHP', + 'JUSH', + 'Nette', + ), $apps); +});