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 2239d570
authored
Jul 05, 2018
by
Sushant
Committed by
GitHub
Jul 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): unable to override rejectOnEmpty (#9632)
1 parent
d65cc7bc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
12 deletions
lib/model.js
test/integration/model/find.test.js
test/integration/model/findAll.test.js
lib/model.js
View file @
2239d57
...
@@ -1672,13 +1672,12 @@ class Model {
...
@@ -1672,13 +1672,12 @@ class Model {
tableNames
[
this
.
getTableName
(
options
)]
=
true
;
tableNames
[
this
.
getTableName
(
options
)]
=
true
;
options
=
Utils
.
cloneDeep
(
options
);
options
=
Utils
.
cloneDeep
(
options
);
_
.
defaults
(
options
,
{
_
.
defaults
(
options
,
{
hooks
:
true
});
hooks
:
true
,
rejectOnEmpty
:
this
.
options
.
rejectOnEmpty
});
// set rejectOnEmpty option from model config
// set rejectOnEmpty option, defaults to model options
options
.
rejectOnEmpty
=
options
.
rejectOnEmpty
||
this
.
options
.
rejectOnEmpty
;
options
.
rejectOnEmpty
=
options
.
hasOwnProperty
(
'rejectOnEmpty'
)
?
options
.
rejectOnEmpty
:
this
.
options
.
rejectOnEmpty
;
return
Promise
.
try
(()
=>
{
return
Promise
.
try
(()
=>
{
this
.
_injectScope
(
options
);
this
.
_injectScope
(
options
);
...
@@ -1904,8 +1903,7 @@ class Model {
...
@@ -1904,8 +1903,7 @@ class Model {
// Bypass a possible overloaded findAll.
// Bypass a possible overloaded findAll.
return
this
.
findAll
(
_
.
defaults
(
options
,
{
return
this
.
findAll
(
_
.
defaults
(
options
,
{
plain
:
true
,
plain
:
true
rejectOnEmpty
:
false
}));
}));
}
}
...
...
test/integration/model/find.test.js
View file @
2239d57
...
@@ -976,6 +976,24 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -976,6 +976,24 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
it
(
'override model options'
,
()
=>
{
const
Model
=
current
.
define
(
'Test'
,
{
username
:
Sequelize
.
STRING
(
100
)
},
{
rejectOnEmpty
:
true
});
return
Model
.
sync
({
force
:
true
})
.
then
(()
=>
{
return
expect
(
Model
.
findOne
({
rejectOnEmpty
:
false
,
where
:
{
username
:
'some-username-that-is-not-used-anywhere'
}
})).
to
.
eventually
.
be
.
deep
.
equal
(
null
);
});
});
it
(
'resolve null when disabled'
,
()
=>
{
it
(
'resolve null when disabled'
,
()
=>
{
const
Model
=
current
.
define
(
'Test'
,
{
const
Model
=
current
.
define
(
'Test'
,
{
username
:
Sequelize
.
STRING
(
100
)
username
:
Sequelize
.
STRING
(
100
)
...
...
test/integration/model/findAll.test.js
View file @
2239d57
...
@@ -1658,7 +1658,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -1658,7 +1658,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it
(
'throws custom error with initialized'
,
()
=>
{
it
(
'throws custom error with initialized'
,
()
=>
{
const
Model
=
current
.
define
(
'Test'
,
{
const
Model
=
current
.
define
(
'Test'
,
{
username
:
Sequelize
.
STRING
(
100
)
username
:
Sequelize
.
STRING
(
100
)
},
{
},
{
...
@@ -1676,7 +1675,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -1676,7 +1675,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it
(
'throws custom error with instance'
,
()
=>
{
it
(
'throws custom error with instance'
,
()
=>
{
const
Model
=
current
.
define
(
'Test'
,
{
const
Model
=
current
.
define
(
'Test'
,
{
username
:
Sequelize
.
STRING
(
100
)
username
:
Sequelize
.
STRING
(
100
)
},
{
},
{
...
@@ -1692,7 +1690,5 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -1692,7 +1690,5 @@ describe(Support.getTestDialectTeaser('Model'), () => {
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
ConnectionError
);
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
ConnectionError
);
});
});
});
});
});
});
});
});
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