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
6e50783e
Commit
6e50783e
authored
Jan 30, 2015
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`yii\mongodb\Query::select` now allows excluding fields
parent
e5e48cd4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
5 deletions
+26
-5
CHANGELOG.md
extensions/mongodb/CHANGELOG.md
+1
-1
Query.php
extensions/mongodb/Query.php
+8
-4
QueryRunTest.php
tests/unit/extensions/mongodb/QueryRunTest.php
+17
-0
No files found.
extensions/mongodb/CHANGELOG.md
View file @
6e50783e
...
@@ -4,7 +4,7 @@ Yii Framework 2 mongodb extension Change Log
...
@@ -4,7 +4,7 @@ Yii Framework 2 mongodb extension Change Log
2.
0.3 under development
2.
0.3 under development
-----------------------
-----------------------
-
no changes in this release.
-
Bug #7010: Fixed
`yii\mongodb\Query::select`
now allows excluding fields (Sammaye, klimov-paul)
2.0.2 January 11, 2015
2.0.2 January 11, 2015
...
...
extensions/mongodb/Query.php
View file @
6e50783e
...
@@ -41,8 +41,8 @@ class Query extends Component implements QueryInterface
...
@@ -41,8 +41,8 @@ class Query extends Component implements QueryInterface
use
QueryTrait
;
use
QueryTrait
;
/**
/**
* @var array the fields of the results to return. For example
, `['name', 'group_id'
]`.
* @var array the fields of the results to return. For example
: `['name', 'group_id']`, `['name' => true, '_id' => false
]`.
*
The "_id" field is always returned. If not set, if
means selecting all columns.
*
Unless directly excluded, the "_id" field is always returned. If not set, it
means selecting all columns.
* @see select()
* @see select()
*/
*/
public
$select
=
[];
public
$select
=
[];
...
@@ -377,8 +377,12 @@ class Query extends Component implements QueryInterface
...
@@ -377,8 +377,12 @@ class Query extends Component implements QueryInterface
{
{
$selectFields
=
[];
$selectFields
=
[];
if
(
!
empty
(
$this
->
select
))
{
if
(
!
empty
(
$this
->
select
))
{
foreach
(
$this
->
select
as
$fieldName
)
{
foreach
(
$this
->
select
as
$key
=>
$value
)
{
$selectFields
[
$fieldName
]
=
true
;
if
(
is_numeric
(
$key
))
{
$selectFields
[
$value
]
=
true
;
}
else
{
$selectFields
[
$key
]
=
$value
;
}
}
}
}
}
return
$selectFields
;
return
$selectFields
;
...
...
tests/unit/extensions/mongodb/QueryRunTest.php
View file @
6e50783e
...
@@ -262,4 +262,21 @@ class QueryRunTest extends MongoDbTestCase
...
@@ -262,4 +262,21 @@ class QueryRunTest extends MongoDbTestCase
$this
->
assertEquals
(
'name1'
,
$rows
[
0
][
'name'
]);
$this
->
assertEquals
(
'name1'
,
$rows
[
0
][
'name'
]);
$this
->
assertEquals
(
'name5'
,
$rows
[
1
][
'name'
]);
$this
->
assertEquals
(
'name5'
,
$rows
[
1
][
'name'
]);
}
}
/**
* @see https://github.com/yiisoft/yii2/issues/7010
*/
public
function
testSelect
()
{
$connection
=
$this
->
getConnection
();
$query
=
new
Query
;
$rows
=
$query
->
from
(
'customer'
)
->
select
([
'name'
=>
true
,
'_id'
=>
false
])
->
limit
(
1
)
->
all
(
$connection
);
$row
=
array_pop
(
$rows
);
$this
->
assertArrayHasKey
(
'name'
,
$row
);
$this
->
assertArrayNotHasKey
(
'address'
,
$row
);
$this
->
assertArrayNotHasKey
(
'_id'
,
$row
);
}
}
}
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