diff --git a/model/SQLQuery.php b/model/SQLQuery.php index b1c9a3dd3..f7d19f603 100644 --- a/model/SQLQuery.php +++ b/model/SQLQuery.php @@ -214,10 +214,11 @@ class SQLQuery { } /** - * Select an additional field + * Select an additional field. * * @param $field The field to select * @param $alias The alias of that field + * @return SQLQuery */ public function selectField($field, $alias = null) { if(!$alias) { @@ -225,6 +226,7 @@ class SQLQuery { else $alias = $field; } $this->select[$alias] = $field; + return $this; } /** diff --git a/tests/model/DbDatetimeTest.php b/tests/model/DbDatetimeTest.php index 295b8fae3..3b351034a 100644 --- a/tests/model/DbDatetimeTest.php +++ b/tests/model/DbDatetimeTest.php @@ -91,11 +91,13 @@ class DbDatetimeTest extends FunctionalTest { $this->matchesRoughly($result, date('Y-m-d H:i:s', strtotime('+1 Day', $this->getDbNow())), 'tomorrow'); $query = new SQLQuery(); - $query->setSelect(array("test" => $this->adapter->datetimeIntervalClause('"Created"', '-15 Minutes'))) - ->setFrom('"DbDateTimeTest_Team"') + $query->setSelect(array()); + $query->selectField($this->adapter->datetimeIntervalClause('"Created"', '-15 Minutes'), 'test') + ->setFrom('"DbDateTimeTest_Team"') ->setLimit(1); + $result = $query->execute()->value(); - $this->matchesRoughly($result, date('Y-m-d H:i:s', strtotime(Dataobject::get_one('DbDateTimeTest_Team')->Created) - 900), '15 Minutes before creating fixture'); + $this->matchesRoughly($result, date('Y-m-d H:i:s', strtotime(DataObject::get_one('DbDateTimeTest_Team')->Created) - 900), '15 Minutes before creating fixture'); } } @@ -116,10 +118,11 @@ class DbDatetimeTest extends FunctionalTest { $this->matchesRoughly($result, -45 * 60, 'now - 45 minutes ahead'); $query = new SQLQuery(); - $query->setSelect(array("test" => $this->adapter->datetimeDifferenceClause('"LastEdited"', '"Created"'))) + $query->setSelect(array()); + $query->selectField($this->adapter->datetimeDifferenceClause('"LastEdited"', '"Created"'), 'test') ->setFrom('"DbDateTimeTest_Team"') ->setLimit(1); - + $result = $query->execute()->value(); $lastedited = Dataobject::get_one('DbDateTimeTest_Team')->LastEdited; $created = Dataobject::get_one('DbDateTimeTest_Team')->Created;