Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
6d6d8d95
Commit
6d6d8d95
authored
Feb 06, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c5cdcab6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
21 deletions
+45
-21
YiiBase.php
framework/YiiBase.php
+1
-1
ActiveQuery.php
framework/db/ar/ActiveQuery.php
+32
-10
ActiveRecord.php
framework/db/ar/ActiveRecord.php
+7
-5
Query.php
framework/db/dao/Query.php
+5
-5
No files found.
framework/YiiBase.php
View file @
6d6d8d95
...
...
@@ -337,7 +337,7 @@ class YiiBase
* Any additional parameters passed to this method will be
* 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
* @throws \yii\base\Exception if the configuration is invalid.
* @see \yii\base\Object::newInstance()
...
...
framework/db/ar/ActiveQuery.php
View file @
6d6d8d95
...
...
@@ -35,22 +35,43 @@ use yii\db\Exception;
*/
class
ActiveQuery
extends
\yii\base\Object
implements
\IteratorAggregate
,
\ArrayAccess
,
\Countable
{
/**
* @var string the name of the ActiveRecord class.
*/
public
$modelClass
;
/**
* @var \yii\db\dao\Query the Query object
*/
public
$query
;
/**
* @var array list of relations that this query should be performed with
*/
public
$with
;
/**
* @var string the table alias to be used for query
*/
public
$tableAlias
;
/**
* @var string the name of the column that the result should be indexed by
*/
public
$indexBy
;
/**
* @var boolean whether to return query results as arrays
*/
public
$asArray
;
/**
* @var array list of scopes that should be applied to this query
*/
public
$scopes
;
/**
* @var array list of query results
*/
public
$records
;
public
$sql
;
/**
* @param string $modelClass the name of the ActiveRecord class.
*/
public
function
__construct
(
$modelClass
)
{
$this
->
modelClass
=
$modelClass
;
...
...
@@ -78,6 +99,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
public
function
exists
()
{
// todo
return
$this
->
select
(
array
(
'1'
))
->
asArray
(
true
)
->
one
()
!==
null
;
}
...
...
@@ -150,7 +172,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Returns an iterator for traversing the items in the vector.
* This method is required by the SPL interface `IteratorAggregate`.
* 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
Vector
Iterator an iterator for traversing the items in the vector.
*/
public
function
getIterator
()
{
...
...
@@ -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];`.
* This is equivalent to [[itemAt]].
* @param integer $offset the offset to retrieve item.
* @return
mixe
d the item at the offset
* @return
ActiveRecor
d the item at the offset
* @throws Exception if the offset is out of range
*/
public
function
offsetGet
(
$offset
)
...
...
@@ -220,7 +242,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* the new item will be appended to the vector.
* Otherwise, the existing item at the offset will be replaced with the new item.
* @param integer $offset the offset to set item
* @param
mixe
d $item the item value
* @param
ActiveRecor
d $item the item value
* @throws Exception if the offset is out of range, or the vector is read only.
*/
public
function
offsetSet
(
$offset
,
$item
)
...
...
@@ -249,7 +271,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
/**
* 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 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
...
...
@@ -258,7 +280,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used.
* @return ActiveQuery the query object itself
*/
public
function
select
(
$columns
=
'*'
,
$option
=
''
)
public
function
select
(
$columns
,
$option
=
''
)
{
$this
->
query
->
select
(
$columns
,
$option
);
return
$this
;
...
...
@@ -277,7 +299,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
/**
* 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.
* 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
...
...
@@ -697,7 +719,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
public
function
joinWith
()
{
// todo: inner join with one or multiple relations
// todo: inner join with one or multiple relations
as filters
}
protected
function
findRecords
()
...
...
framework/db/ar/ActiveRecord.php
View file @
6d6d8d95
...
...
@@ -26,7 +26,7 @@ use yii\db\dao\Query;
abstract
class
ActiveRecord
extends
\yii\base\Model
{
/**
* @var
* @var
ActiveMetaData[] list of AR metadata indexed by AR class names
*/
private
static
$_md
;
...
...
@@ -52,10 +52,9 @@ abstract class ActiveRecord extends \yii\base\Model
}
/**
* @static
* @param string|array|Query $q
* @return ActiveQuery
* @throws
\yii\db\
Exception
* @throws Exception
*/
public
static
function
find
(
$q
=
null
)
{
...
...
@@ -103,9 +102,12 @@ abstract class ActiveRecord extends \yii\base\Model
}
public
static
function
createActiveQuery
()
/**
* @return ActiveFinder
*/
public
static
function
createActiveFinder
()
{
return
new
Active
Query
(
'\\'
.
get_called_class
());
return
new
Active
Finder
(
'\\'
.
get_called_class
());
}
/**
...
...
framework/db/dao/Query.php
View file @
6d6d8d95
...
...
@@ -377,7 +377,7 @@ class Query extends \yii\base\Object
/**
* 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 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
...
...
@@ -386,7 +386,7 @@ class Query extends \yii\base\Object
* in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used.
* @return Query the query object itself
*/
public
function
select
(
$columns
=
'*'
,
$option
=
''
)
public
function
select
(
$columns
,
$option
=
''
)
{
$this
->
select
=
$columns
;
$this
->
selectOption
=
$option
;
...
...
@@ -406,7 +406,7 @@ class Query extends \yii\base\Object
/**
* 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.
* 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
...
...
@@ -838,7 +838,7 @@ class Query extends \yii\base\Object
/**
* 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)`.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return Query the query object itself
...
...
@@ -852,7 +852,7 @@ class Query extends \yii\base\Object
/**
* 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)`.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return Query the query object itself
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment