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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletions
lib/instance.js
test/unit/instance/changed.test.js
lib/instance.js
View file @
8eafb4e
...
@@ -339,9 +339,14 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
...
@@ -339,9 +339,14 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
}
}
// Convert date fields to real date objects
// Convert date fields to real date objects
if
(
this
.
Model
.
_hasDateAttributes
&&
this
.
Model
.
_isDateAttribute
(
key
)
&&
value
!==
null
&&
value
!==
undefined
&&
!
(
value
instanceof
Date
)
&&
!
value
.
_isSequelizeMethod
)
{
if
(
this
.
Model
.
_hasDateAttributes
&&
this
.
Model
.
_isDateAttribute
(
key
)
&&
!!
value
&&
!
value
.
_isSequelizeMethod
)
{
if
(
!
(
value
instanceof
Date
))
{
value
=
new
Date
(
value
);
value
=
new
Date
(
value
);
}
}
if
(
originalValue
&&
value
.
getTime
()
===
originalValue
.
getTime
())
{
return
;
}
}
}
}
// Convert boolean-ish values to booleans
// Convert boolean-ish values to booleans
...
...
test/unit/instance/changed.test.js
View file @
8eafb4e
...
@@ -62,6 +62,22 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
...
@@ -62,6 +62,22 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
expect
(
user
.
changed
(
'birthdate'
)).
to
.
equal
(
true
);
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
()
{
it
(
'should return true for changed JSON with same object'
,
function
()
{
var
user
=
this
.
User
.
build
({
var
user
=
this
.
User
.
build
({
meta
:
{
meta
:
{
...
...
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