diff --git a/framework/db/ar/ActiveFinder.php b/framework/db/ar/ActiveFinder.php index b5806d8..c668007 100644 --- a/framework/db/ar/ActiveFinder.php +++ b/framework/db/ar/ActiveFinder.php @@ -10,6 +10,7 @@ namespace yii\db\ar; +use yii\base\Object; use yii\base\VectorIterator; use yii\db\dao\Query; use yii\db\Exception; @@ -45,6 +46,10 @@ class ActiveFinder extends \yii\base\Object * @var \yii\db\dao\Connection */ public $connection; + /** + * @var ActiveQuery + */ + public $query; public function __construct($connection) { diff --git a/framework/db/ar/ActiveQuery.php b/framework/db/ar/ActiveQuery.php index 5f8c888..9b2f7e8 100644 --- a/framework/db/ar/ActiveQuery.php +++ b/framework/db/ar/ActiveQuery.php @@ -12,6 +12,7 @@ namespace yii\db\ar; use yii\base\VectorIterator; use yii\db\dao\BaseQuery; +use yii\db\dao\Expression; use yii\db\Exception; /** @@ -155,12 +156,13 @@ class ActiveQuery extends BaseQuery implements \IteratorAggregate, \ArrayAccess, public function value() { - return 0; + $result = $this->asArray()->one(); + return $result === null ? null : reset($result); } 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, } 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); - } - } }