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 ca0cbaa3
authored
Aug 15, 2018
by
andrewAtPaymentRails
Committed by
Sushant
Aug 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): bulkCreate should populate dataValues directly (#9797)
1 parent
6804e27b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
lib/model.js
test/integration/model.test.js
test/integration/model/bulk-create.test.js
lib/model.js
View file @
ca0cbaa
...
...
@@ -2608,7 +2608,7 @@ class Model {
if
(
Array
.
isArray
(
results
))
{
results
.
forEach
((
result
,
i
)
=>
{
if
(
instances
[
i
]
&&
!
instances
[
i
].
get
(
this
.
primaryKeyAttribute
))
{
instances
[
i
]
&&
instances
[
i
].
set
(
this
.
primaryKeyAttribute
,
result
[
this
.
primaryKeyField
],
{
raw
:
true
})
;
instances
[
i
]
.
dataValues
[
this
.
primaryKeyField
]
=
result
[
this
.
primaryKeyField
]
;
}
});
}
...
...
@@ -2623,7 +2623,7 @@ class Model {
instance
.
dataValues
[
this
.
rawAttributes
[
attr
].
field
]
!==
undefined
&&
this
.
rawAttributes
[
attr
].
field
!==
attr
)
{
instance
.
set
(
attr
,
instance
.
dataValues
[
this
.
rawAttributes
[
attr
].
field
])
;
instance
.
dataValues
[
attr
]
=
instance
.
dataValues
[
this
.
rawAttributes
[
attr
].
field
]
;
delete
instance
.
dataValues
[
this
.
rawAttributes
[
attr
].
field
];
}
instance
.
_previousDataValues
[
attr
]
=
instance
.
dataValues
[
attr
];
...
...
test/integration/model.test.js
View file @
ca0cbaa
...
...
@@ -2848,13 +2848,13 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return
this
.
sequelize
.
sync
({
force
:
true
});
});
describe
(
'bulkCreate
errors
'
,
()
=>
{
it
(
'should return array of errors if validate and individualHooks are true'
,
function
()
{
describe
(
'bulkCreate'
,
()
=>
{
it
(
'
errors -
should return array of errors if validate and individualHooks are true'
,
function
()
{
const
data
=
[{
username
:
null
},
{
username
:
null
},
{
username
:
null
}];
const
user
=
this
.
sequelize
.
define
(
'User
s
'
,
{
const
user
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
...
...
@@ -2865,10 +2865,41 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}
});
return
expect
(
user
.
bulkCreate
(
data
,
{
validate
:
true
,
individualHooks
:
true
})).
to
.
be
.
rejectedWith
(
Promise
.
AggregateError
);
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
expect
(
user
.
bulkCreate
(
data
,
{
validate
:
true
,
individualHooks
:
true
})).
to
.
be
.
rejectedWith
(
Promise
.
AggregateError
);
});
});
it
(
'should not use setter when renaming fields in dataValues'
,
function
()
{
const
user
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
field
:
'data'
,
get
()
{
const
val
=
this
.
getDataValue
(
'username'
);
return
val
.
substring
(
0
,
val
.
length
-
1
);
},
set
(
val
)
{
if
(
val
.
indexOf
(
'!'
)
>
-
1
)
{
throw
new
Error
(
'val should not include a "!"'
);
}
this
.
setDataValue
(
'username'
,
val
+
'!'
);
}
}
});
const
data
=
[{
username
:
'jon'
}];
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
user
.
bulkCreate
(
data
).
then
(()
=>
{
return
user
.
findAll
().
then
(
users1
=>
{
expect
(
users1
[
0
].
username
).
to
.
equal
(
'jon'
);
});
});
});
});
});
});
test/integration/model/bulk-create.test.js
View file @
ca0cbaa
...
...
@@ -626,7 +626,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return
Maya
.
bulkCreate
([
M2
]);
}).
spread
(
m
=>
{
// only attributes are returned, no fields are mixed
// only attributes are returned, no fields are mixed
expect
(
m
.
createdAt
).
to
.
be
.
ok
;
expect
(
m
.
created_at
).
to
.
not
.
exist
;
expect
(
m
.
secret_given
).
to
.
not
.
exist
;
...
...
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