Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selection::resetOrder #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Selection::resetOrder #54

wants to merge 2 commits into from

Conversation

hranicka
Copy link
Contributor

In some cases it would be nice to have an option reset current order on the query.

I see that corresponding method ::setOrder is present in SqlBuilder since v2.3 but it's not used in Selection.
So I've added option for ORDER BY clause reset.

What do you think about that?

@@ -14,12 +14,29 @@ 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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added also DESC keyword to previous test because without it result was the same as defined order in SQL fixture.

@hrach
Copy link
Contributor

hrach commented Feb 25, 2015

I never had strong opinition, how many methods should be reflected in selection.

public function resetOrder()
{
$this->emptyResultSet();
call_user_func_array(array($this->sqlBuilder, 'setOrder'), [[], []]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for call_user_func_, $this->sqlBuilder->setOrder([], []); is sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanx. Why not call it directly if it has no magical arguments. Copy & Paste of ::order :(

@hranicka
Copy link
Contributor Author

@hrach It failing on PHP 5.3 - this version is no longer supported?

@redwormik
Copy link
Contributor

5.3 is failing, because it doesn't support the [] array syntax

@hranicka
Copy link
Contributor Author

hranicka commented Mar 6, 2015

@redwormik Thx, I'm stupid or blind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants