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 a1bf40dd
authored
Jul 17, 2018
by
Sushant
Committed by
GitHub
Jul 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(bulkCreate): dont map dataValue to fields for individualHooks:true (#9672)
1 parent
da3571c9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
17 deletions
lib/model.js
test/integration/model/bulk-create.test.js
lib/model.js
View file @
a1bf40d
...
...
@@ -2553,22 +2553,6 @@ class Model {
});
}
}).
then
(()
=>
{
for
(
const
instance
of
instances
)
{
const
values
=
instance
.
dataValues
;
// set createdAt/updatedAt attributes
if
(
createdAtAttr
&&
!
values
[
createdAtAttr
])
{
values
[
createdAtAttr
]
=
now
;
options
.
fields
.
indexOf
(
createdAtAttr
)
===
-
1
&&
options
.
fields
.
push
(
createdAtAttr
);
}
if
(
updatedAtAttr
&&
!
values
[
updatedAtAttr
])
{
values
[
updatedAtAttr
]
=
now
;
options
.
fields
.
indexOf
(
updatedAtAttr
)
===
-
1
&&
options
.
fields
.
push
(
updatedAtAttr
);
}
instance
.
dataValues
=
Utils
.
mapValueFieldNames
(
values
,
options
.
fields
,
this
);
}
if
(
options
.
individualHooks
)
{
// Create each instance individually
return
Promise
.
map
(
instances
,
instance
=>
{
...
...
@@ -2587,6 +2571,20 @@ class Model {
// Create all in one query
// Recreate records from instances to represent any changes made in hooks or validation
records
=
instances
.
map
(
instance
=>
{
const
values
=
instance
.
dataValues
;
// set createdAt/updatedAt attributes
if
(
createdAtAttr
&&
!
values
[
createdAtAttr
])
{
values
[
createdAtAttr
]
=
now
;
options
.
fields
.
indexOf
(
createdAtAttr
)
===
-
1
&&
options
.
fields
.
push
(
createdAtAttr
);
}
if
(
updatedAtAttr
&&
!
values
[
updatedAtAttr
])
{
values
[
updatedAtAttr
]
=
now
;
options
.
fields
.
indexOf
(
updatedAtAttr
)
===
-
1
&&
options
.
fields
.
push
(
updatedAtAttr
);
}
instance
.
dataValues
=
Utils
.
mapValueFieldNames
(
values
,
options
.
fields
,
this
);
return
_
.
omit
(
instance
.
dataValues
,
this
.
_virtualAttributes
);
});
...
...
@@ -2613,7 +2611,6 @@ class Model {
});
}
}).
then
(()
=>
{
// map fields back to attributes
instances
.
forEach
(
instance
=>
{
for
(
const
attr
in
this
.
rawAttributes
)
{
...
...
test/integration/model/bulk-create.test.js
View file @
a1bf40d
...
...
@@ -114,6 +114,33 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it
(
'should not map instance dataValues to fields with individualHooks: true'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'user'
,
{
name
:
Sequelize
.
STRING
,
type
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
field
:
'user_type'
},
createdAt
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
field
:
'created_at'
},
updatedAt
:
{
type
:
Sequelize
.
DATE
,
field
:
'modified_at'
}
});
return
User
.
sync
({
force
:
true
}).
then
(()
=>
{
return
User
.
bulkCreate
([
{
name
:
'James'
,
type
:
'A'
},
{
name
:
'Alan'
,
type
:
'Z'
}
],
{
individualHooks
:
true
});
});
});
it
(
'should not insert NULL for unused fields'
,
function
()
{
const
Beer
=
this
.
sequelize
.
define
(
'Beer'
,
{
style
:
Sequelize
.
STRING
,
...
...
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