Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 8eafb4e9
authored
Jul 14, 2015
by
joao.bortolozzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing date comparison on instance.set()
1 parent
789c3dc9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
lib/instance.js
test/unit/instance/changed.test.js
lib/instance.js
View file @
8eafb4e
...
...
@@ -339,8 +339,13 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
}
// Convert date fields to real date objects
if
(
this
.
Model
.
_hasDateAttributes
&&
this
.
Model
.
_isDateAttribute
(
key
)
&&
value
!==
null
&&
value
!==
undefined
&&
!
(
value
instanceof
Date
)
&&
!
value
.
_isSequelizeMethod
)
{
value
=
new
Date
(
value
);
if
(
this
.
Model
.
_hasDateAttributes
&&
this
.
Model
.
_isDateAttribute
(
key
)
&&
!!
value
&&
!
value
.
_isSequelizeMethod
)
{
if
(
!
(
value
instanceof
Date
))
{
value
=
new
Date
(
value
);
}
if
(
originalValue
&&
value
.
getTime
()
===
originalValue
.
getTime
())
{
return
;
}
}
}
...
...
test/unit/instance/changed.test.js
View file @
8eafb4e
...
...
@@ -62,6 +62,22 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
expect
(
user
.
changed
(
'birthdate'
)).
to
.
equal
(
true
);
});
it
(
'should return false for two instances with same value'
,
function
()
{
var
milliseconds
=
1436921941088
;
var
firstDate
=
new
Date
(
milliseconds
);
var
secondDate
=
new
Date
(
milliseconds
);
var
user
=
this
.
User
.
build
({
birthdate
:
firstDate
},
{
isNewRecord
:
false
,
raw
:
true
});
user
.
set
(
'birthdate'
,
secondDate
);
expect
(
user
.
changed
(
'birthdate'
)).
to
.
equal
(
false
);
});
it
(
'should return true for changed JSON with same object'
,
function
()
{
var
user
=
this
.
User
.
build
({
meta
:
{
...
...
@@ -79,4 +95,4 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
expect
(
user
.
changed
(
'meta'
)).
to
.
equal
(
true
);
});
});
});
\ No newline at end of file
});
Write
Preview
Markdown
is supported
Attach a file
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 post a comment