Commit 4222c9d0 by Qiang Xue

Merge branch 'master' of git.yiisoft.com:yii2

Conflicts: framework/db/ar/ActiveFinder.php framework/db/ar/ActiveQuery.php
parents 3210a217 71fc3dbe
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace yii\db\ar; namespace yii\db\ar;
use yii\base\Object;
use yii\base\VectorIterator; use yii\base\VectorIterator;
use yii\db\dao\Query; use yii\db\dao\Query;
use yii\db\Exception; use yii\db\Exception;
...@@ -45,6 +46,10 @@ class ActiveFinder extends \yii\base\Object ...@@ -45,6 +46,10 @@ class ActiveFinder extends \yii\base\Object
* @var \yii\db\dao\Connection * @var \yii\db\dao\Connection
*/ */
public $connection; public $connection;
/**
* @var ActiveQuery
*/
public $query;
public function __construct($connection) public function __construct($connection)
{ {
......
...@@ -12,6 +12,7 @@ namespace yii\db\ar; ...@@ -12,6 +12,7 @@ namespace yii\db\ar;
use yii\base\VectorIterator; use yii\base\VectorIterator;
use yii\db\dao\BaseQuery; use yii\db\dao\BaseQuery;
use yii\db\dao\Expression;
use yii\db\Exception; use yii\db\Exception;
/** /**
...@@ -155,12 +156,13 @@ class ActiveQuery extends BaseQuery implements \IteratorAggregate, \ArrayAccess, ...@@ -155,12 +156,13 @@ class ActiveQuery extends BaseQuery implements \IteratorAggregate, \ArrayAccess,
public function value() public function value()
{ {
return 0; $result = $this->asArray()->one();
return $result === null ? null : reset($result);
} }
public function exists() public function exists()
{ {
return $this->select(array('1'))->asArray(true)->one() !== null; return $this->select(array(new Expression('1')))->asArray()->one() !== null;
} }
/** /**
...@@ -294,14 +296,4 @@ class ActiveQuery extends BaseQuery implements \IteratorAggregate, \ArrayAccess, ...@@ -294,14 +296,4 @@ class ActiveQuery extends BaseQuery implements \IteratorAggregate, \ArrayAccess,
} }
unset($this->records[$offset]); unset($this->records[$offset]);
} }
protected function findRecords($all = true)
{
$finder = new ActiveFinder($this->getDbConnection());
if (!empty($this->with)) {
return $finder->findRecordsWithRelations();
} else {
return $finder->findRecords($this, $all);
}
}
} }
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