Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
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
sinan
laravel-mongodb
Commits
a2f4eca3
Commit
a2f4eca3
authored
Dec 22, 2015
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix getDirty check for dates, fixes #373
parent
712c88a6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
Model.php
src/Jenssegers/Mongodb/Model.php
+23
-0
ModelTest.php
tests/ModelTest.php
+10
-0
No files found.
src/Jenssegers/Mongodb/Model.php
View file @
a2f4eca3
...
@@ -355,6 +355,29 @@ abstract class Model extends BaseModel {
...
@@ -355,6 +355,29 @@ abstract class Model extends BaseModel {
return
$attributes
;
return
$attributes
;
}
}
/**
* Determine if the new and old values for a given key are numerically equivalent.
*
* @param string $key
* @return bool
*/
protected
function
originalIsNumericallyEquivalent
(
$key
)
{
$current
=
$this
->
attributes
[
$key
];
$original
=
$this
->
original
[
$key
];
// Date comparison.
if
(
in_array
(
$key
,
$this
->
getDates
()))
{
$current
=
$current
instanceof
MongoDate
?
$this
->
asDateTime
(
$current
)
:
$current
;
$original
=
$original
instanceof
MongoDate
?
$this
->
asDateTime
(
$original
)
:
$original
;
return
$current
==
$original
;
}
return
parent
::
originalIsNumericallyEquivalent
(
$key
);
}
/**
/**
* Remove one or more fields.
* Remove one or more fields.
*
*
...
...
tests/ModelTest.php
View file @
a2f4eca3
...
@@ -490,4 +490,14 @@ class ModelTest extends TestCase {
...
@@ -490,4 +490,14 @@ class ModelTest extends TestCase {
$this
->
assertEquals
(
'Paris'
,
$user
->
{
'address.city'
});
$this
->
assertEquals
(
'Paris'
,
$user
->
{
'address.city'
});
}
}
public
function
testGetDirtyDates
()
{
$user
=
new
User
();
$user
->
setRawAttributes
([
'name'
=>
'John Doe'
,
'birthday'
=>
new
DateTime
(
'19 august 1989'
)],
true
);
$this
->
assertEmpty
(
$user
->
getDirty
());
$user
->
birthday
=
new
DateTime
(
'19 august 1989'
);
$this
->
assertEmpty
(
$user
->
getDirty
());
}
}
}
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