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
df023545
Commit
df023545
authored
Nov 17, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed `yii\mongodb\ActiveRecord` saves `null` as `_id`, if attributes are empty
parent
d0ee41e4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
1 deletion
+18
-1
ActiveRecord.php
extensions/mongodb/ActiveRecord.php
+3
-1
CHANGELOG.md
extensions/mongodb/CHANGELOG.md
+1
-0
ActiveRecordTest.php
tests/unit/extensions/mongodb/ActiveRecordTest.php
+14
-0
No files found.
extensions/mongodb/ActiveRecord.php
View file @
df023545
...
...
@@ -222,7 +222,9 @@ abstract class ActiveRecord extends BaseActiveRecord
if
(
empty
(
$values
))
{
$currentAttributes
=
$this
->
getAttributes
();
foreach
(
$this
->
primaryKey
()
as
$key
)
{
$values
[
$key
]
=
isset
(
$currentAttributes
[
$key
])
?
$currentAttributes
[
$key
]
:
null
;
if
(
isset
(
$currentAttributes
[
$key
]))
{
$values
[
$key
]
=
$currentAttributes
[
$key
];
}
}
}
$newId
=
static
::
getCollection
()
->
insert
(
$values
);
...
...
extensions/mongodb/CHANGELOG.md
View file @
df023545
...
...
@@ -4,6 +4,7 @@ Yii Framework 2 mongodb extension Change Log
2.
0.1 under development
-----------------------
-
Bug #6026: Fixed
`yii\mongodb\ActiveRecord`
saves
`null`
as
`_id`
, if attributes are empty (klimov-paul)
-
Enh #3855: Added debug toolbar panel for MongoDB (klimov-paul)
-
Enh #5592: Added support for 'findAndModify' operation at
`yii\mongodb\Query`
and
`yii\mongodb\ActiveQuery`
(klimov-paul)
...
...
tests/unit/extensions/mongodb/ActiveRecordTest.php
View file @
df023545
...
...
@@ -275,4 +275,18 @@ class ActiveRecordTest extends MongoDbTestCase
$this
->
assertTrue
(
$customer
instanceof
Customer
);
$this
->
assertEquals
(
$newName
,
$customer
->
name
);
}
/**
* @depends testInsert
*
* @see https://github.com/yiisoft/yii2/issues/6026
*/
public
function
testInsertEmptyAttributes
()
{
$record
=
new
Customer
();
$record
->
save
(
false
);
$this
->
assertTrue
(
$record
->
_id
instanceof
\MongoId
);
$this
->
assertFalse
(
$record
->
isNewRecord
);
}
}
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