Commit 6d6d8d95 by Qiang Xue

.

parent c5cdcab6
...@@ -337,7 +337,7 @@ class YiiBase ...@@ -337,7 +337,7 @@ class YiiBase
* Any additional parameters passed to this method will be * Any additional parameters passed to this method will be
* passed to the constructor of the object being created. * passed to the constructor of the object being created.
* *
* @param mixed $config the configuration. It can be either a string or an array. * @param string|array $config the configuration. It can be either a string or an array.
* @return mixed the created object * @return mixed the created object
* @throws \yii\base\Exception if the configuration is invalid. * @throws \yii\base\Exception if the configuration is invalid.
* @see \yii\base\Object::newInstance() * @see \yii\base\Object::newInstance()
......
...@@ -35,22 +35,43 @@ use yii\db\Exception; ...@@ -35,22 +35,43 @@ use yii\db\Exception;
*/ */
class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \ArrayAccess, \Countable class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \ArrayAccess, \Countable
{ {
/**
* @var string the name of the ActiveRecord class.
*/
public $modelClass; public $modelClass;
/** /**
* @var \yii\db\dao\Query the Query object * @var \yii\db\dao\Query the Query object
*/ */
public $query; public $query;
/**
* @var array list of relations that this query should be performed with
*/
public $with; public $with;
/**
* @var string the table alias to be used for query
*/
public $tableAlias; public $tableAlias;
/**
* @var string the name of the column that the result should be indexed by
*/
public $indexBy; public $indexBy;
/**
* @var boolean whether to return query results as arrays
*/
public $asArray; public $asArray;
/**
* @var array list of scopes that should be applied to this query
*/
public $scopes; public $scopes;
/**
* @var array list of query results
*/
public $records; public $records;
public $sql; public $sql;
/**
* @param string $modelClass the name of the ActiveRecord class.
*/
public function __construct($modelClass) public function __construct($modelClass)
{ {
$this->modelClass = $modelClass; $this->modelClass = $modelClass;
...@@ -78,6 +99,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array ...@@ -78,6 +99,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
public function exists() public function exists()
{ {
// todo
return $this->select(array('1'))->asArray(true)->one() !== null; return $this->select(array('1'))->asArray(true)->one() !== null;
} }
...@@ -150,7 +172,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array ...@@ -150,7 +172,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Returns an iterator for traversing the items in the vector. * Returns an iterator for traversing the items in the vector.
* This method is required by the SPL interface `IteratorAggregate`. * This method is required by the SPL interface `IteratorAggregate`.
* It will be implicitly called when you use `foreach` to traverse the vector. * It will be implicitly called when you use `foreach` to traverse the vector.
* @return Iterator an iterator for traversing the items in the vector. * @return VectorIterator an iterator for traversing the items in the vector.
*/ */
public function getIterator() public function getIterator()
{ {
...@@ -201,7 +223,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array ...@@ -201,7 +223,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* It is implicitly called when you use something like `$value = $vector[$offset];`. * It is implicitly called when you use something like `$value = $vector[$offset];`.
* This is equivalent to [[itemAt]]. * This is equivalent to [[itemAt]].
* @param integer $offset the offset to retrieve item. * @param integer $offset the offset to retrieve item.
* @return mixed the item at the offset * @return ActiveRecord the item at the offset
* @throws Exception if the offset is out of range * @throws Exception if the offset is out of range
*/ */
public function offsetGet($offset) public function offsetGet($offset)
...@@ -220,7 +242,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array ...@@ -220,7 +242,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* the new item will be appended to the vector. * the new item will be appended to the vector.
* Otherwise, the existing item at the offset will be replaced with the new item. * Otherwise, the existing item at the offset will be replaced with the new item.
* @param integer $offset the offset to set item * @param integer $offset the offset to set item
* @param mixed $item the item value * @param ActiveRecord $item the item value
* @throws Exception if the offset is out of range, or the vector is read only. * @throws Exception if the offset is out of range, or the vector is read only.
*/ */
public function offsetSet($offset, $item) public function offsetSet($offset, $item)
...@@ -249,7 +271,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array ...@@ -249,7 +271,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
/** /**
* Sets the SELECT part of the query. * Sets the SELECT part of the query.
* @param mixed $columns the columns to be selected. Defaults to '*', meaning all columns. * @param string|array $columns the columns to be selected.
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')). * Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')).
* Columns can contain table prefixes (e.g. "tbl_user.id") and/or column aliases (e.g. "tbl_user.id AS user_id"). * Columns can contain table prefixes (e.g. "tbl_user.id") and/or column aliases (e.g. "tbl_user.id AS user_id").
* The method will automatically quote the column names unless a column contains some parenthesis * The method will automatically quote the column names unless a column contains some parenthesis
...@@ -258,7 +280,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array ...@@ -258,7 +280,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used. * in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used.
* @return ActiveQuery the query object itself * @return ActiveQuery the query object itself
*/ */
public function select($columns = '*', $option = '') public function select($columns, $option = '')
{ {
$this->query->select($columns, $option); $this->query->select($columns, $option);
return $this; return $this;
...@@ -277,7 +299,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array ...@@ -277,7 +299,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
/** /**
* Sets the FROM part of the query. * Sets the FROM part of the query.
* @param mixed $tables the table(s) to be selected from. This can be either a string (e.g. 'tbl_user') * @param string|array $tables the table(s) to be selected from. This can be either a string (e.g. 'tbl_user')
* or an array (e.g. array('tbl_user', 'tbl_profile')) specifying one or several table names. * or an array (e.g. array('tbl_user', 'tbl_profile')) specifying one or several table names.
* Table names can contain schema prefixes (e.g. 'public.tbl_user') and/or table aliases (e.g. 'tbl_user u'). * Table names can contain schema prefixes (e.g. 'public.tbl_user') and/or table aliases (e.g. 'tbl_user u').
* The method will automatically quote the table names unless it contains some parenthesis * The method will automatically quote the table names unless it contains some parenthesis
...@@ -697,7 +719,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array ...@@ -697,7 +719,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
public function joinWith() public function joinWith()
{ {
// todo: inner join with one or multiple relations // todo: inner join with one or multiple relations as filters
} }
protected function findRecords() protected function findRecords()
......
...@@ -26,7 +26,7 @@ use yii\db\dao\Query; ...@@ -26,7 +26,7 @@ use yii\db\dao\Query;
abstract class ActiveRecord extends \yii\base\Model abstract class ActiveRecord extends \yii\base\Model
{ {
/** /**
* @var * @var ActiveMetaData[] list of AR metadata indexed by AR class names
*/ */
private static $_md; private static $_md;
...@@ -52,10 +52,9 @@ abstract class ActiveRecord extends \yii\base\Model ...@@ -52,10 +52,9 @@ abstract class ActiveRecord extends \yii\base\Model
} }
/** /**
* @static
* @param string|array|Query $q * @param string|array|Query $q
* @return ActiveQuery * @return ActiveQuery
* @throws \yii\db\Exception * @throws Exception
*/ */
public static function find($q = null) public static function find($q = null)
{ {
...@@ -103,9 +102,12 @@ abstract class ActiveRecord extends \yii\base\Model ...@@ -103,9 +102,12 @@ abstract class ActiveRecord extends \yii\base\Model
} }
public static function createActiveQuery() /**
* @return ActiveFinder
*/
public static function createActiveFinder()
{ {
return new ActiveQuery('\\' . get_called_class()); return new ActiveFinder('\\' . get_called_class());
} }
/** /**
......
...@@ -377,7 +377,7 @@ class Query extends \yii\base\Object ...@@ -377,7 +377,7 @@ class Query extends \yii\base\Object
/** /**
* Sets the SELECT part of the query. * Sets the SELECT part of the query.
* @param string|array $columns the columns to be selected. Defaults to '*', meaning all columns. * @param string|array $columns the columns to be selected.
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')). * Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')).
* Columns can contain table prefixes (e.g. "tbl_user.id") and/or column aliases (e.g. "tbl_user.id AS user_id"). * Columns can contain table prefixes (e.g. "tbl_user.id") and/or column aliases (e.g. "tbl_user.id AS user_id").
* The method will automatically quote the column names unless a column contains some parenthesis * The method will automatically quote the column names unless a column contains some parenthesis
...@@ -386,7 +386,7 @@ class Query extends \yii\base\Object ...@@ -386,7 +386,7 @@ class Query extends \yii\base\Object
* in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used. * in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used.
* @return Query the query object itself * @return Query the query object itself
*/ */
public function select($columns = '*', $option = '') public function select($columns, $option = '')
{ {
$this->select = $columns; $this->select = $columns;
$this->selectOption = $option; $this->selectOption = $option;
...@@ -406,7 +406,7 @@ class Query extends \yii\base\Object ...@@ -406,7 +406,7 @@ class Query extends \yii\base\Object
/** /**
* Sets the FROM part of the query. * Sets the FROM part of the query.
* @param mixed $tables the table(s) to be selected from. This can be either a string (e.g. 'tbl_user') * @param string|array $tables the table(s) to be selected from. This can be either a string (e.g. 'tbl_user')
* or an array (e.g. array('tbl_user', 'tbl_profile')) specifying one or several table names. * or an array (e.g. array('tbl_user', 'tbl_profile')) specifying one or several table names.
* Table names can contain schema prefixes (e.g. 'public.tbl_user') and/or table aliases (e.g. 'tbl_user u'). * Table names can contain schema prefixes (e.g. 'public.tbl_user') and/or table aliases (e.g. 'tbl_user u').
* The method will automatically quote the table names unless it contains some parenthesis * The method will automatically quote the table names unless it contains some parenthesis
...@@ -838,7 +838,7 @@ class Query extends \yii\base\Object ...@@ -838,7 +838,7 @@ class Query extends \yii\base\Object
/** /**
* Sets the parameters to be bound to the query. * Sets the parameters to be bound to the query.
* @param array list of query parameter values indexed by parameter placeholders. * @param array $params list of query parameter values indexed by parameter placeholders.
* For example, `array(':name'=>'Dan', ':age'=>31)`. * For example, `array(':name'=>'Dan', ':age'=>31)`.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. * Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return Query the query object itself * @return Query the query object itself
...@@ -852,7 +852,7 @@ class Query extends \yii\base\Object ...@@ -852,7 +852,7 @@ class Query extends \yii\base\Object
/** /**
* Adds additional parameters to be bound to the query. * Adds additional parameters to be bound to the query.
* @param array list of query parameter values indexed by parameter placeholders. * @param array $params list of query parameter values indexed by parameter placeholders.
* For example, `array(':name'=>'Dan', ':age'=>31)`. * For example, `array(':name'=>'Dan', ':age'=>31)`.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. * Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return Query the query object itself * @return Query the query object itself
......
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