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 191819fa
authored
Feb 27, 2018
by
Aaron Williams
Committed by
Sushant
Feb 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model/upsert): support options.validation (#8872)
1 parent
60c04d97
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
lib/model.js
test/integration/model/upsert.test.js
lib/model.js
View file @
191819f
...
@@ -2233,7 +2233,8 @@ class Model {
...
@@ -2233,7 +2233,8 @@ class Model {
static
upsert
(
values
,
options
)
{
static
upsert
(
values
,
options
)
{
options
=
Object
.
assign
({
options
=
Object
.
assign
({
hooks
:
true
,
hooks
:
true
,
returning
:
false
returning
:
false
,
validate
:
true
},
Utils
.
cloneDeep
(
options
||
{}));
},
Utils
.
cloneDeep
(
options
||
{}));
options
.
model
=
this
;
options
.
model
=
this
;
...
@@ -2247,7 +2248,11 @@ class Model {
...
@@ -2247,7 +2248,11 @@ class Model {
options
.
fields
=
Object
.
keys
(
instance
.
_changed
);
options
.
fields
=
Object
.
keys
(
instance
.
_changed
);
}
}
return
instance
.
validate
(
options
).
then
(()
=>
{
return
Promise
.
try
(()
=>
{
if
(
options
.
validate
)
{
return
instance
.
validate
(
options
);
}
}).
then
(()
=>
{
// Map field names
// Map field names
const
updatedDataValues
=
_
.
pick
(
instance
.
dataValues
,
Object
.
keys
(
instance
.
_changed
));
const
updatedDataValues
=
_
.
pick
(
instance
.
dataValues
,
Object
.
keys
(
instance
.
_changed
));
const
insertValues
=
Utils
.
mapValueFieldNames
(
instance
.
dataValues
,
instance
.
attributes
,
this
);
const
insertValues
=
Utils
.
mapValueFieldNames
(
instance
.
dataValues
,
instance
.
attributes
,
this
);
...
...
test/integration/model/upsert.test.js
View file @
191819f
...
@@ -196,6 +196,29 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -196,6 +196,29 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return
expect
(
User
.
upsert
({
email
:
'notanemail'
})).
to
.
eventually
.
be
.
rejectedWith
(
this
.
sequelize
.
ValidationError
);
return
expect
(
User
.
upsert
({
email
:
'notanemail'
})).
to
.
eventually
.
be
.
rejectedWith
(
this
.
sequelize
.
ValidationError
);
});
});
it
(
'supports skipping validations'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'user'
,
{
email
:
{
type
:
Sequelize
.
STRING
,
validate
:
{
isEmail
:
true
}
}
});
const
options
=
{
validate
:
false
};
return
User
.
sync
({
force
:
true
})
.
then
(()
=>
User
.
upsert
({
id
:
1
,
email
:
'notanemail'
},
options
))
.
then
(
created
=>
{
if
(
dialect
===
'sqlite'
)
{
expect
(
created
).
to
.
be
.
undefined
;
}
else
{
expect
(
created
).
to
.
be
.
okay
;
}
});
});
it
(
'works with BLOBs'
,
function
()
{
it
(
'works with BLOBs'
,
function
()
{
return
this
.
User
.
upsert
({
id
:
42
,
username
:
'john'
,
blob
:
new
Buffer
(
'kaj'
)
}).
bind
(
this
).
then
(
function
(
created
)
{
return
this
.
User
.
upsert
({
id
:
42
,
username
:
'john'
,
blob
:
new
Buffer
(
'kaj'
)
}).
bind
(
this
).
then
(
function
(
created
)
{
if
(
dialect
===
'sqlite'
)
{
if
(
dialect
===
'sqlite'
)
{
...
...
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