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 36a51ab3
authored
Jan 03, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests & stuff
1 parent
278d0a2c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
26 deletions
lib/dao.js
test/dao/values.test.js
lib/dao.js
View file @
36a51ab
...
@@ -18,8 +18,6 @@ module.exports = (function() {
...
@@ -18,8 +18,6 @@ module.exports = (function() {
this
.
isNewRecord
=
options
.
isNewRecord
this
.
isNewRecord
=
options
.
isNewRecord
initValues
.
call
(
this
,
values
,
options
)
initValues
.
call
(
this
,
values
,
options
)
this
.
isDirty
=
options
.
isDirty
}
}
Utils
.
_
.
extend
(
DAO
.
prototype
,
Mixin
.
prototype
)
Utils
.
_
.
extend
(
DAO
.
prototype
,
Mixin
.
prototype
)
...
@@ -49,7 +47,7 @@ module.exports = (function() {
...
@@ -49,7 +47,7 @@ module.exports = (function() {
Object
.
defineProperty
(
DAO
.
prototype
,
'isDirty'
,
{
Object
.
defineProperty
(
DAO
.
prototype
,
'isDirty'
,
{
get
:
function
()
{
get
:
function
()
{
return
this
.
changed
()
return
!!
this
.
changed
()
}
}
})
})
...
@@ -160,7 +158,7 @@ module.exports = (function() {
...
@@ -160,7 +158,7 @@ module.exports = (function() {
value
=
!!
value
value
=
!!
value
}
}
this
.
_previousDataValues
[
key
]
=
originalValue
if
(
originalValue
!==
value
)
this
.
_previousDataValues
[
key
]
=
originalValue
this
.
dataValues
[
key
]
=
value
this
.
dataValues
[
key
]
=
value
}
}
}
}
...
@@ -174,9 +172,11 @@ module.exports = (function() {
...
@@ -174,9 +172,11 @@ module.exports = (function() {
}
}
return
false
return
false
}
}
return
Object
.
keys
(
this
.
dataValues
).
some
(
function
(
key
)
{
var
changed
=
Object
.
keys
(
this
.
dataValues
).
filter
(
function
(
key
)
{
return
this
.
changed
(
key
)
return
this
.
changed
(
key
)
}.
bind
(
this
))
}.
bind
(
this
))
return
changed
.
length
?
changed
:
false
}
}
DAO
.
prototype
.
previous
=
function
(
key
)
{
DAO
.
prototype
.
previous
=
function
(
key
)
{
...
@@ -244,10 +244,11 @@ module.exports = (function() {
...
@@ -244,10 +244,11 @@ module.exports = (function() {
options
.
fields
=
this
.
attributes
options
.
fields
=
this
.
attributes
}
}
var
self
=
this
var
self
=
this
,
values
=
options
.
fields
?
{}
:
(
this
.
options
.
includeNames
?
_
.
omit
(
this
.
dataValues
,
this
.
options
.
includeNames
)
:
this
.
dataValues
)
,
values
=
options
.
fields
?
{}
:
(
this
.
options
.
includeNames
?
_
.
omit
(
this
.
dataValues
,
this
.
options
.
includeNames
)
:
this
.
dataValues
)
,
updatedAtAttr
=
Utils
.
_
.
underscoredIf
(
this
.
__options
.
updatedAt
,
this
.
__options
.
underscored
)
,
updatedAtAttr
=
Utils
.
_
.
underscoredIf
(
this
.
__options
.
updatedAt
,
this
.
__options
.
underscored
)
,
createdAtAttr
=
Utils
.
_
.
underscoredIf
(
this
.
__options
.
createdAt
,
this
.
__options
.
underscored
)
,
createdAtAttr
=
Utils
.
_
.
underscoredIf
(
this
.
__options
.
createdAt
,
this
.
__options
.
underscored
)
,
originalValues
=
Utils
.
_
.
clone
(
this
.
dataValues
)
if
(
options
.
fields
)
{
if
(
options
.
fields
)
{
if
(
self
.
__options
.
timestamps
)
{
if
(
self
.
__options
.
timestamps
)
{
...
@@ -365,19 +366,14 @@ module.exports = (function() {
...
@@ -365,19 +366,14 @@ module.exports = (function() {
self
.
set
(
values
,
{
raw
:
true
})
self
.
set
(
values
,
{
raw
:
true
})
self
.
QueryInterface
[
query
].
apply
(
self
.
QueryInterface
,
args
)
self
.
QueryInterface
[
query
].
apply
(
self
.
QueryInterface
,
args
)
.
on
(
'sql'
,
function
(
sql
)
{
.
proxy
(
emitter
,
{
events
:
[
'sql'
,
'error'
]})
emitter
.
emit
(
'sql'
,
sql
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
)
})
.
success
(
function
(
result
)
{
.
success
(
function
(
result
)
{
self
.
__factory
.
runHooks
(
'after'
+
hook
,
result
.
values
,
function
(
err
,
newValues
)
{
self
.
__factory
.
runHooks
(
'after'
+
hook
,
result
.
values
,
function
(
err
,
newValues
)
{
if
(
!!
err
)
{
if
(
!!
err
)
{
return
emitter
.
emit
(
'error'
,
err
)
return
emitter
.
emit
(
'error'
,
err
)
}
}
result
.
dataValues
=
_
.
extend
(
result
.
dataValues
,
newValues
)
result
.
_previousDataValues
=
result
.
dataValues
=
_
.
extend
(
result
.
dataValues
,
newValues
)
emitter
.
emit
(
'success'
,
result
)
emitter
.
emit
(
'success'
,
result
)
})
})
})
})
...
...
test/dao/values.test.js
View file @
36a51ab
...
@@ -145,7 +145,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -145,7 +145,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
var
user
=
User
.
build
()
var
user
=
User
.
build
()
user
.
set
(
'name'
,
'Mick Hansen'
)
user
.
set
(
'name'
,
'Mick Hansen'
)
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
false
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
false
expect
(
user
.
changed
()).
to
.
be
.
false
expect
(
user
.
changed
()).
not
.
to
.
be
.
ok
expect
(
user
.
isDirty
).
to
.
be
.
false
expect
(
user
.
isDirty
).
to
.
be
.
false
})
})
...
@@ -159,7 +159,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -159,7 +159,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
user
.
set
(
'name'
,
'Mick Hansen'
)
user
.
set
(
'name'
,
'Mick Hansen'
)
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
true
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
true
expect
(
user
.
changed
()).
to
.
be
.
true
expect
(
user
.
changed
()).
to
.
be
.
ok
expect
(
user
.
isDirty
).
to
.
be
.
true
expect
(
user
.
isDirty
).
to
.
be
.
true
})
})
...
@@ -168,20 +168,38 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -168,20 +168,38 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
name
:
{
type
:
DataTypes
.
STRING
}
name
:
{
type
:
DataTypes
.
STRING
}
})
})
User
.
sync
().
done
(
function
(
err
)
{
var
user
=
User
.
build
({
name
:
'Jan Meier'
})
user
.
set
(
'name'
,
'Mick Hansen'
)
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
true
expect
(
user
.
changed
()).
to
.
be
.
ok
expect
(
user
.
isDirty
).
to
.
be
.
true
user
.
save
().
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
false
expect
(
user
.
changed
()).
not
.
to
.
be
.
ok
expect
(
user
.
isDirty
).
to
.
be
.
false
done
()
})
})
})
it
(
'setting the same value twice should not impact the result'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
{
type
:
DataTypes
.
STRING
}
})
var
user
=
User
.
build
({
var
user
=
User
.
build
({
name
:
'Jan Meier'
name
:
'Jan Meier'
})
})
user
.
set
(
'name'
,
'Mick Hansen'
)
user
.
set
(
'name'
,
'Mick Hansen'
)
user
.
set
(
'name'
,
'Mick Hansen'
)
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
true
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
true
expect
(
user
.
changed
()).
to
.
be
.
true
expect
(
user
.
changed
()).
to
.
be
.
ok
expect
(
user
.
isDirty
).
to
.
be
.
true
expect
(
user
.
isDirty
).
to
.
be
.
true
expect
(
user
.
previous
(
'name'
)).
to
.
equal
(
'Jan Meier'
)
user
.
save
().
done
(
function
(
err
)
{
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
false
expect
(
user
.
changed
()).
to
.
be
.
false
expect
(
user
.
isDirty
).
to
.
be
.
false
done
()
})
})
})
})
})
...
...
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