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 a9524acf
authored
Aug 01, 2013
by
Michael Storgaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed areChanged to didChange and added support for underscore in setter
1 parent
2f17a525
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
lib/dao.js
lib/utils.js
lib/dao.js
View file @
a9524ac
...
@@ -87,7 +87,7 @@ module.exports = (function() {
...
@@ -87,7 +87,7 @@ module.exports = (function() {
DAO
.
prototype
.
get
=
DAO
.
prototype
.
getDataValue
DAO
.
prototype
.
get
=
DAO
.
prototype
.
getDataValue
DAO
.
prototype
.
setDataValue
=
function
(
name
,
value
)
{
DAO
.
prototype
.
setDataValue
=
function
(
name
,
value
)
{
if
(
Utils
.
areChanged
(
this
.
dataValues
[
name
],
value
))
{
if
(
Utils
.
didChange
(
this
.
dataValues
[
name
],
value
))
{
this
.
isDirty
=
true
this
.
isDirty
=
true
}
}
this
.
dataValues
[
name
]
=
value
this
.
dataValues
[
name
]
=
value
...
@@ -240,7 +240,7 @@ module.exports = (function() {
...
@@ -240,7 +240,7 @@ module.exports = (function() {
(
self
.
attributes
.
indexOf
(
attr
)
>
-
1
)
(
self
.
attributes
.
indexOf
(
attr
)
>
-
1
)
)
)
if
(
updateAllowed
)
{
if
(
updateAllowed
)
{
if
(
Utils
.
areChanged
(
self
[
attr
],
value
))
{
if
(
Utils
.
didChange
(
self
[
attr
],
value
))
{
isDirty
=
true
isDirty
=
true
}
}
self
[
attr
]
=
value
self
[
attr
]
=
value
...
@@ -346,9 +346,13 @@ module.exports = (function() {
...
@@ -346,9 +346,13 @@ module.exports = (function() {
if
(
has
!==
true
)
{
if
(
has
!==
true
)
{
this
.
__defineGetter__
(
attribute
,
has
.
get
||
function
()
{
return
this
.
dataValues
[
attribute
];
});
this
.
__defineGetter__
(
attribute
,
has
.
get
||
function
()
{
return
this
.
dataValues
[
attribute
];
});
this
.
__defineSetter__
(
attribute
,
has
.
set
||
function
(
v
)
{
this
.
__defineSetter__
(
attribute
,
has
.
set
||
function
(
v
)
{
if
(
Utils
.
areChanged
(
this
.
dataValues
[
attribute
],
v
))
{
if
(
Utils
.
didChange
(
this
.
dataValues
[
attribute
],
v
))
{
//Only dirty the object if the change is not due to id, touchedAt, createdAt or updatedAt being initiated
//Only dirty the object if the change is not due to id, touchedAt, createdAt or updatedAt being initiated
if
(
this
.
dataValues
[
attribute
]
||
(
attribute
!=
'id'
&&
attribute
!=
'touchedAt'
&&
attribute
!=
'createdAt'
&&
attribute
!=
'updatedAt'
))
{
var
updatedAtAttr
=
this
.
__options
.
underscored
?
'updated_at'
:
'updatedAt'
,
createdAtAttr
=
this
.
__options
.
underscored
?
'created_at'
:
'createdAt'
,
touchedAtAttr
=
this
.
__options
.
underscored
?
'touched_at'
:
'touchedAt'
if
(
this
.
dataValues
[
attribute
]
||
(
attribute
!=
'id'
&&
attribute
!=
touchedAtAttr
&&
attribute
!=
createdAtAttr
&&
attribute
!=
updatedAtAttr
))
{
this
.
isDirty
=
true
this
.
isDirty
=
true
}
}
}
}
...
...
lib/utils.js
View file @
a9524ac
...
@@ -252,7 +252,7 @@ var Utils = module.exports = {
...
@@ -252,7 +252,7 @@ var Utils = module.exports = {
isHash
:
function
(
obj
)
{
isHash
:
function
(
obj
)
{
return
Utils
.
_
.
isObject
(
obj
)
&&
!
Array
.
isArray
(
obj
);
return
Utils
.
_
.
isObject
(
obj
)
&&
!
Array
.
isArray
(
obj
);
},
},
areChanged
:
function
(
attrValue
,
value
)
{
didChange
:
function
(
attrValue
,
value
)
{
//If attribute value is Date, check value as a date
//If attribute value is Date, check value as a date
if
(
Utils
.
_
.
isDate
(
attrValue
)
&&
!
Utils
.
_
.
isDate
(
value
))
{
if
(
Utils
.
_
.
isDate
(
attrValue
)
&&
!
Utils
.
_
.
isDate
(
value
))
{
value
=
new
Date
(
value
)
value
=
new
Date
(
value
)
...
@@ -260,7 +260,7 @@ var Utils = module.exports = {
...
@@ -260,7 +260,7 @@ var Utils = module.exports = {
if
(
Utils
.
_
.
isDate
(
attrValue
))
{
if
(
Utils
.
_
.
isDate
(
attrValue
))
{
return
attrValue
.
valueOf
()
!==
value
.
valueOf
()
return
attrValue
.
valueOf
()
!==
value
.
valueOf
()
}
}
//If both
are
them are empty, don't set as changed
//If both
of
them are empty, don't set as changed
if
((
attrValue
===
undefined
||
attrValue
===
null
||
attrValue
===
''
)
&&
(
value
===
undefined
||
value
===
null
||
value
===
''
))
{
if
((
attrValue
===
undefined
||
attrValue
===
null
||
attrValue
===
''
)
&&
(
value
===
undefined
||
value
===
null
||
value
===
''
))
{
return
false
return
false
}
}
...
...
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