Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixing the problem with order and \Zend\Db\Sql\Expression #3017

Closed
wants to merge 2 commits into from

3 participants

@shoseph

No description provided.

@Maks3w
Collaborator

Please add a test case

@ralphschindler
Collaborator

So your feature request is that you want to use expressions with order()? What do you need to do with an exression object that you can't already achieve with a string or array notation?

@shoseph

I found the problem when I needed to use the function "rand ()" to return the MySql random fields.

I checked that was implemented logic Sql \ Expression, I enabled only for "order ()".

@shoseph

Ps. In Zend Framework 1 was recommended to use "zend_db_expr()"

@ralphschindler
Collaborator

Merged to develop, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  library/Zend/Db/Sql/Select.php
@@ -340,6 +340,8 @@ public function order($order)
} else {
$order = (array) $order;
}
+ } elseif ($order instanceof Expression){
+ $order = array($order);
}
foreach ($order as $k => $v) {
if (is_string($k)) {
View
4 tests/ZendTest/Db/Sql/SelectTest.php
@@ -260,6 +260,10 @@ public function testOrder()
$select = new Select;
$select->order(array('name ASC', 'age DESC'));
$this->assertEquals(array('name ASC', 'age DESC'), $select->getRawState('order'));
+
+ $select = new Select;
+ $select->order(new \Zend\db\sql\Expression('id DESC'));
+ $this->assertEquals('id DESC', current($select->getRawState('order'))->getExpression());
}
/**
Something went wrong with that request. Please try again.