From d8feaeb93b4408312032fa75cdb832de7e4e8bae Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sat, 23 Nov 2013 03:20:49 +0100 Subject: [PATCH] refactored redis AR Query::scalar() --- framework/yii/redis/ActiveQuery.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/framework/yii/redis/ActiveQuery.php b/framework/yii/redis/ActiveQuery.php index eabd843..2174901 100644 --- a/framework/yii/redis/ActiveQuery.php +++ b/framework/yii/redis/ActiveQuery.php @@ -56,7 +56,7 @@ class ActiveQuery extends \yii\base\Component implements ActiveQueryInterface * Executes the query and returns all results as an array. * @param Connection $db the database connection used to execute the query. * If this parameter is not given, the `db` application component will be used. - * @return ActiveRecord[] the query results. If the query results in nothing, an empty array will be returned. + * @return array|ActiveRecord[] the query results. If the query results in nothing, an empty array will be returned. */ public function all($db = null) { @@ -215,20 +215,20 @@ class ActiveQuery extends \yii\base\Component implements ActiveQueryInterface /** * Returns the query result as a scalar value. - * The value returned will be the first column in the first row of the query results. - * @param string $column name of the column to select + * The value returned will be the specified attribute in the first record of the query results. + * @param string $attribute name of the attribute to select * @param Connection $db the database connection used to execute the query. * If this parameter is not given, the `db` application component will be used. - * @return string|boolean the value of the first column in the first row of the query result. - * False is returned if the query result is empty. + * @return string the value of the specified attribute in the first record of the query result. + * Null is returned if the query result is empty. */ - public function scalar($column, $db = null) + public function scalar($attribute, $db = null) { $record = $this->one($db); - if ($record === null) { - return false; + if ($record !== null) { + return $record->$attribute; } else { - return $record->$column; + return null; } }