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
face5262
Commit
face5262
authored
Apr 08, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3027 from Alex-Code/addSelect
addSelect method for Query
parents
93d18dcb
d133abf6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
0 deletions
+26
-0
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Query.php
framework/db/Query.php
+20
-0
QueryTest.php
tests/unit/framework/db/QueryTest.php
+5
-0
No files found.
framework/CHANGELOG.md
View file @
face5262
...
...
@@ -189,6 +189,7 @@ Yii Framework 2 Change Log
-
Enh: Added support to allow an event handler to be inserted at the beginning of the existing event handler list (qiangxue)
-
Enh: Improved action filter and action execution flow by supporting installing action filters at controller, module and application levels (qiangxue)
-
Enh: Added
`isAssociative()`
and
`isIndexed()`
to
`yii\helpers\ArrayHelper`
(qiangxue)
-
Enh: Added
`addSelect`
to
`yii\db\Query`
(Alex-Code)
-
Chg #47: Changed Markdown library to cebe/markdown and adjusted Markdown helper API (cebe)
-
Chg #735: Added back
`ActiveField::hiddenInput()`
(qiangxue)
-
Chg #1186: Changed
`Sort`
to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue)
...
...
framework/db/Query.php
View file @
face5262
...
...
@@ -409,6 +409,26 @@ class Query extends Component implements QueryInterface
}
/**
* Add more columns to the SELECT part of the query.
* @param string|array $columns the columns to add to the select.
* @return static the query object itself
* @see select()
*/
public
function
addSelect
(
$columns
)
{
if
(
!
is_array
(
$columns
))
{
$columns
=
preg_split
(
'/\s*,\s*/'
,
trim
(
$columns
),
-
1
,
PREG_SPLIT_NO_EMPTY
);
}
if
(
$this
->
select
===
null
)
{
$this
->
select
=
$columns
;
}
else
{
$this
->
select
=
array_merge
(
$this
->
select
,
$columns
);
}
return
$this
;
}
/**
* Sets the value indicating whether to SELECT DISTINCT or not.
* @param boolean $value whether to SELECT DISTINCT or not.
* @return static the query object itself
...
...
tests/unit/framework/db/QueryTest.php
View file @
face5262
...
...
@@ -24,6 +24,11 @@ class QueryTest extends DatabaseTestCase
$this
->
assertEquals
([
'id'
,
'name'
],
$query
->
select
);
$this
->
assertTrue
(
$query
->
distinct
);
$this
->
assertEquals
(
'something'
,
$query
->
selectOption
);
$query
=
new
Query
();
$query
->
select
(
'id, name'
);
$query
->
addSelect
(
'email'
);
$this
->
assertEquals
([
'id'
,
'name'
,
'email'
],
$query
->
select
);
}
public
function
testFrom
()
...
...
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