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 d546f80d
authored
Nov 09, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dao#save and DaoFactory#create can handle an object as first param
1 parent
4f6a4426
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
lib/dao-factory.js
lib/dao.js
lib/dao-factory.js
View file @
d546f80
...
@@ -535,6 +535,10 @@ module.exports = (function() {
...
@@ -535,6 +535,10 @@ module.exports = (function() {
Utils
.
validateParameter
(
values
,
Object
,
{
optional
:
true
})
Utils
.
validateParameter
(
values
,
Object
,
{
optional
:
true
})
Utils
.
validateParameter
(
fieldsOrOptions
,
Object
,
{
deprecated
:
Array
,
optional
:
true
})
Utils
.
validateParameter
(
fieldsOrOptions
,
Object
,
{
deprecated
:
Array
,
optional
:
true
})
if
(
fieldsOrOptions
instanceof
Array
)
{
fieldsOrOptions
=
{
fields
:
fieldsOrOptions
}
}
return
this
.
build
(
values
).
save
(
fieldsOrOptions
)
return
this
.
build
(
values
).
save
(
fieldsOrOptions
)
}
}
...
...
lib/dao.js
View file @
d546f80
...
@@ -96,26 +96,32 @@ module.exports = (function() {
...
@@ -96,26 +96,32 @@ module.exports = (function() {
// if an array with field names is passed to save()
// if an array with field names is passed to save()
// only those fields will be updated
// only those fields will be updated
DAO
.
prototype
.
save
=
function
(
fields
,
options
)
{
DAO
.
prototype
.
save
=
function
(
fields
OrOptions
,
options
)
{
var
self
=
this
var
self
=
this
,
values
=
fields
?
{}
:
this
.
dataValues
,
values
=
fields
OrOptions
?
{}
:
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
)
if
(
fields
)
{
if
(
fieldsOrOptions
instanceof
Array
)
{
fieldsOrOptions
=
{
fields
:
fieldsOrOptions
}
}
options
=
Utils
.
_
.
extend
({},
options
,
fieldsOrOptions
)
if
(
options
.
fields
)
{
if
(
self
.
__options
.
timestamps
)
{
if
(
self
.
__options
.
timestamps
)
{
if
(
fields
.
indexOf
(
updatedAtAttr
)
===
-
1
)
{
if
(
options
.
fields
.
indexOf
(
updatedAtAttr
)
===
-
1
)
{
fields
.
push
(
updatedAtAttr
)
options
.
fields
.
push
(
updatedAtAttr
)
}
}
if
(
fields
.
indexOf
(
createdAtAttr
)
===
-
1
&&
this
.
isNewRecord
===
true
)
{
if
(
options
.
fields
.
indexOf
(
createdAtAttr
)
===
-
1
&&
this
.
isNewRecord
===
true
)
{
fields
.
push
(
createdAtAttr
)
options
.
fields
.
push
(
createdAtAttr
)
}
}
}
}
var
tmpVals
=
self
.
dataValues
var
tmpVals
=
self
.
dataValues
fields
.
forEach
(
function
(
field
)
{
options
.
fields
.
forEach
(
function
(
field
)
{
if
(
tmpVals
[
field
]
!==
undefined
)
{
if
(
tmpVals
[
field
]
!==
undefined
)
{
values
[
field
]
=
tmpVals
[
field
]
values
[
field
]
=
tmpVals
[
field
]
}
}
...
...
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