Browse Source

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

Conflicts:
	framework/db/ar/ActiveFinder.php
	framework/db/ar/ActiveQuery.php
tags/2.0.0-beta
Qiang Xue 13 years ago
parent
commit
4222c9d09a
  1. 5
      framework/db/ar/ActiveFinder.php
  2. 16
      framework/db/ar/ActiveQuery.php

5
framework/db/ar/ActiveFinder.php

@ -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
* @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)
{ {

16
framework/db/ar/ActiveQuery.php

@ -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,
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,
} }
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);
}
}
} }

Loading…
Cancel
Save