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 3909a477
authored
Sep 23, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2333 from sequelize/fix2225
Fix #2225
2 parents
c84e73cb
4cae20ec
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
7 deletions
lib/dao.js
lib/dao.js
View file @
3909a47
...
@@ -647,12 +647,15 @@ module.exports = (function() {
...
@@ -647,12 +647,15 @@ module.exports = (function() {
// private
// private
var
initValues
=
function
(
values
,
options
)
{
var
initValues
=
function
(
values
,
options
)
{
// set id to null if not passed as value, a newly created dao has no id
// set id to null if not passed as value, a newly created dao has no id
var
defaults
=
this
.
hasPrimaryKeys
?
{}
:
{
id
:
null
},
var
defaults
,
key
;
key
,
primaryKeyAttribute
;
values
=
values
&&
_
.
clone
(
values
)
||
{}
values
=
values
&&
_
.
clone
(
values
)
||
{}
if
(
options
.
isNewRecord
)
{
if
(
options
.
isNewRecord
)
{
defaults
=
{};
if
(
this
.
hasDefaultValues
)
{
if
(
this
.
hasDefaultValues
)
{
Utils
.
_
.
each
(
this
.
defaultValues
,
function
(
valueFn
,
key
)
{
Utils
.
_
.
each
(
this
.
defaultValues
,
function
(
valueFn
,
key
)
{
if
(
!
defaults
.
hasOwnProperty
(
key
))
{
if
(
!
defaults
.
hasOwnProperty
(
key
))
{
...
@@ -661,6 +664,19 @@ module.exports = (function() {
...
@@ -661,6 +664,19 @@ module.exports = (function() {
})
})
}
}
// set pk to null if not passed as value, a newly created dao has no id
// removing this breaks bulkCreate
// do after default values since it might have UUID as a default value
if
(
this
.
Model
.
_hasPrimaryKeys
)
{
primaryKeyAttribute
=
this
.
model
.
primaryKeyAttributes
[
0
];
}
else
{
primaryKeyAttribute
=
'id'
;
}
if
(
!
defaults
.
hasOwnProperty
(
primaryKeyAttribute
))
{
defaults
[
primaryKeyAttribute
]
=
null
;
}
if
(
this
.
Model
.
_timestampAttributes
.
createdAt
&&
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
])
{
if
(
this
.
Model
.
_timestampAttributes
.
createdAt
&&
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
])
{
this
.
dataValues
[
this
.
Model
.
_timestampAttributes
.
createdAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
]);
this
.
dataValues
[
this
.
Model
.
_timestampAttributes
.
createdAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
]);
delete
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
];
delete
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
];
...
@@ -675,11 +691,12 @@ module.exports = (function() {
...
@@ -675,11 +691,12 @@ module.exports = (function() {
this
.
dataValues
[
this
.
Model
.
_timestampAttributes
.
deletedAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
Model
.
_timestampAttributes
.
deletedAt
]);
this
.
dataValues
[
this
.
Model
.
_timestampAttributes
.
deletedAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
Model
.
_timestampAttributes
.
deletedAt
]);
delete
defaults
[
this
.
Model
.
_timestampAttributes
.
deletedAt
];
delete
defaults
[
this
.
Model
.
_timestampAttributes
.
deletedAt
];
}
}
}
if
(
Object
.
keys
(
defaults
).
length
)
{
if
(
Object
.
keys
(
defaults
).
length
)
{
for
(
key
in
defaults
)
{
for
(
key
in
defaults
)
{
if
(
!
values
.
hasOwnProperty
(
key
))
{
if
(
!
values
.
hasOwnProperty
(
key
))
{
values
[
key
]
=
Utils
.
toDefaultValue
(
defaults
[
key
])
values
[
key
]
=
Utils
.
toDefaultValue
(
defaults
[
key
])
}
}
}
}
}
}
}
...
...
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