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 b634cd87
authored
Oct 27, 2018
by
Takashi Sasaki
Committed by
Sushant
Oct 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): validate virtual attribute (#9947) (#10085)
1 parent
122bd174
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletions
lib/model.js
test/integration/model/bulk-create.test.js
lib/model.js
View file @
b634cd8
...
@@ -2500,7 +2500,7 @@ class Model {
...
@@ -2500,7 +2500,7 @@ class Model {
ignoreDuplicates
:
false
ignoreDuplicates
:
false
},
options
);
},
options
);
options
.
fields
=
options
.
fields
||
Object
.
keys
(
this
.
table
Attributes
);
options
.
fields
=
options
.
fields
||
Object
.
keys
(
this
.
raw
Attributes
);
const
dialect
=
this
.
sequelize
.
options
.
dialect
;
const
dialect
=
this
.
sequelize
.
options
.
dialect
;
...
...
test/integration/model/bulk-create.test.js
View file @
b634cd8
...
@@ -689,5 +689,51 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -689,5 +689,51 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
});
});
describe
(
'virtual attribute'
,
()
=>
{
beforeEach
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'user'
,
{
password
:
{
type
:
Sequelize
.
VIRTUAL
,
validate
:
{
customValidator
:
()
=>
{
throw
new
Error
(
'always invalid'
);
}
}
}
});
});
it
(
'sholud validate'
,
function
()
{
return
this
.
User
.
sync
({
force
:
true
})
.
then
(()
=>
this
.
User
.
bulkCreate
([
{
password
:
'password'
}
],
{
validate
:
true
}))
.
then
(()
=>
{
expect
.
fail
();
},
error
=>
{
expect
(
error
.
length
).
to
.
equal
(
1
);
expect
(
error
[
0
].
message
).
to
.
match
(
/.*always invalid.*/
);
});
});
it
(
'shold not validate'
,
function
()
{
return
this
.
User
.
sync
({
force
:
true
})
.
then
(()
=>
this
.
User
.
bulkCreate
([
{
password
:
'password'
}
],
{
validate
:
false
}))
.
then
(
users
=>
{
expect
(
users
.
length
).
to
.
equal
(
1
);
})
.
then
(()
=>
this
.
User
.
bulkCreate
([
{
password
:
'password'
}
]))
.
then
(
users
=>
{
expect
(
users
.
length
).
to
.
equal
(
1
);
});
});
});
});
});
});
});
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