Commit d8feaeb9 by Carsten Brandt

refactored redis AR Query::scalar()

parent a07facf4
...@@ -56,7 +56,7 @@ class ActiveQuery extends \yii\base\Component implements ActiveQueryInterface ...@@ -56,7 +56,7 @@ class ActiveQuery extends \yii\base\Component implements ActiveQueryInterface
* Executes the query and returns all results as an array. * Executes the query and returns all results as an array.
* @param Connection $db the database connection used to execute the query. * @param Connection $db the database connection used to execute the query.
* If this parameter is not given, the `db` application component will be used. * 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) public function all($db = null)
{ {
...@@ -215,20 +215,20 @@ class ActiveQuery extends \yii\base\Component implements ActiveQueryInterface ...@@ -215,20 +215,20 @@ class ActiveQuery extends \yii\base\Component implements ActiveQueryInterface
/** /**
* Returns the query result as a scalar value. * Returns the query result as a scalar value.
* The value returned will be the first column in the first row of the query results. * The value returned will be the specified attribute in the first record of the query results.
* @param string $column name of the column to select * @param string $attribute name of the attribute to select
* @param Connection $db the database connection used to execute the query. * @param Connection $db the database connection used to execute the query.
* If this parameter is not given, the `db` application component will be used. * 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. * @return string the value of the specified attribute in the first record of the query result.
* False is returned if the query result is empty. * 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); $record = $this->one($db);
if ($record === null) { if ($record !== null) {
return false; return $record->$attribute;
} else { } else {
return $record->$column; return null;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment