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 5dd5e303
authored
Mar 02, 2016
by
Sushant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(#4091) check if options.where is an acceptable POJO
1 parent
6f4cdcfa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
13 deletions
lib/model.js
test/unit/model/destroy.test.js
test/unit/model/update.test.js
lib/model.js
View file @
5dd5e30
...
...
@@ -2285,6 +2285,10 @@ Model.prototype.destroy = function(options) {
throw
new
Error
(
'Missing where or truncate attribute in the options parameter of model.destroy.'
);
}
if
(
!
options
.
truncate
&&
!
_
.
isPlainObject
(
options
.
where
)
&&
!
_
.
isArray
(
options
.
where
)
&&
options
.
where
.
_isSequelizeMethod
!==
true
)
{
throw
new
Error
(
'Expected plain object, array or sequelize method in the options.where parameter of model.destroy.'
);
}
options
=
Utils
.
_
.
extend
({
hooks
:
true
,
individualHooks
:
false
,
...
...
@@ -2445,6 +2449,10 @@ Model.prototype.update = function(values, options) {
throw
new
Error
(
'Missing where attribute in the options parameter passed to update.'
);
}
if
(
!
_
.
isPlainObject
(
options
.
where
)
&&
!
_
.
isArray
(
options
.
where
)
&&
options
.
where
.
_isSequelizeMethod
!==
true
)
{
throw
new
Error
(
'Expected plain object, array or sequelize method in the options.where parameter of model.update.'
);
}
options
=
Utils
.
_
.
extend
({
validate
:
true
,
hooks
:
true
,
...
...
test/unit/model/destroy.test.js
View file @
5dd5e30
...
...
@@ -19,37 +19,40 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
before
(
function
()
{
this
.
stub
Upda
te
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'bulkDelete'
,
function
()
{
this
.
stub
Dele
te
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'bulkDelete'
,
function
()
{
return
Promise
.
resolve
([]);
});
});
beforeEach
(
function
()
{
this
.
options
=
{
where
:
{
secretValue
:
'1'
}}
this
.
cloneOptions
=
_
.
clone
(
this
.
options
);
this
.
stub
Upda
te
.
reset
();
this
.
deloptions
=
{
where
:
{
secretValue
:
'1'
}};
this
.
cloneOptions
=
_
.
clone
(
this
.
del
options
);
this
.
stub
Dele
te
.
reset
();
});
afterEach
(
function
()
{
delete
this
.
options
;
delete
this
.
del
options
;
delete
this
.
cloneOptions
;
});
after
(
function
()
{
this
.
stub
Upda
te
.
restore
();
this
.
stub
Dele
te
.
restore
();
});
it
(
'properly clones options'
,
function
()
{
var
self
=
this
;
return
User
.
destroy
(
self
.
options
).
bind
(
this
).
then
(
function
(
e
)
{
expect
(
self
.
options
).
to
.
be
.
deep
.
eql
(
self
.
cloneOptions
);
return
User
.
destroy
(
self
.
del
options
).
bind
(
this
).
then
(
function
(
e
)
{
expect
(
self
.
del
options
).
to
.
be
.
deep
.
eql
(
self
.
cloneOptions
);
});
});
it
(
'can detect complexe objects'
,
function
()
{
var
self
=
this
;
var
where
=
function
()
{
this
.
secretValue
=
'1'
;
}
return
expect
(
User
.
destroy
({
where
:
new
where
})).
to
.
eventually
.
be
.
rejectedWith
(
Error
);
var
Where
=
function
()
{
this
.
secretValue
=
'1'
;
};
expect
(
function
()
{
User
.
destroy
({
where
:
new
Where
()});
}).
to
.
throw
();
});
});
});
test/unit/model/update.test.js
View file @
5dd5e30
...
...
@@ -57,8 +57,12 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'can detect complexe objects'
,
function
()
{
var
self
=
this
;
var
where
=
function
()
{
this
.
secretValue
=
'1'
;
}
return
expect
(
User
.
update
(
self
.
updates
,
{
where
:
new
where
})).
to
.
eventually
.
be
.
rejectedWith
(
Error
);
var
Where
=
function
()
{
this
.
secretValue
=
'1'
;
};
expect
(
function
()
{
User
.
update
(
self
.
updates
,
{
where
:
new
Where
()});
}).
to
.
throw
();
});
});
});
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