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 00831299
authored
Jun 16, 2015
by
ns3777k
Committed by
Jan Aagaard Meier
Jun 17, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added functionality to remove hooks. Merge pull request #3947 from ns3777k:feature/remove-hooks
1 parent
323b8cc5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
1 deletions
changelog.md
lib/hooks.js
test/integration/hooks.test.js
changelog.md
View file @
0083129
...
...
@@ -3,6 +3,7 @@
-
[
FIXED
]
Creating and dropping enums in transaction, only for PostgreSQL
[
#3782
](
https://github.com/sequelize/sequelize/issues/3782
)
-
[
FIXED
]
$or/$and inside a where clause always expects the input to be an array
[
#3767
](
https://github.com/sequelize/sequelize/issues/3767
)
-
[
ADDED
]
Unique constraints may now include custom error messages
-
[
ADDED
]
It's possible now to remove a hook by name
# 3.2.0
-
[
FEATURE
]
Add support for new option
`targetKey`
in a belongs-to relationship for situations where the target key is not the id field.
...
...
lib/hooks.js
View file @
0083129
...
...
@@ -162,6 +162,31 @@ var Hooks = {
return
this
;
},
/**
* Remove hook from the model
*
* @param {String} hookType
* @param {String} name
*/
removeHook
:
function
(
hookType
,
name
)
{
hookType
=
hookAliases
[
hookType
]
||
hookType
;
if
(
!
this
.
hasHook
(
hookType
))
{
return
this
;
}
this
.
options
.
hooks
[
hookType
]
=
this
.
options
.
hooks
[
hookType
].
filter
(
function
(
hook
)
{
// don't remove unnamed hooks
if
(
typeof
hook
===
'function'
)
{
return
true
;
}
return
typeof
hook
===
'object'
&&
hook
.
name
!==
name
;
});
return
this
;
},
/*
* Check whether the mode has any hooks of this type
*
...
...
test/integration/hooks.test.js
View file @
0083129
...
...
@@ -5623,7 +5623,7 @@ describe(Support.getTestDialectTeaser('Hooks'), function() {
});
describe
(
'#addHook'
,
function
()
{
it
(
'should add additi
no
al hook when previous exists'
,
function
()
{
it
(
'should add additi
on
al hook when previous exists'
,
function
()
{
var
hook1
=
sinon
.
spy
()
,
hook2
=
sinon
.
spy
()
,
Model
;
...
...
@@ -5644,4 +5644,27 @@ describe(Support.getTestDialectTeaser('Hooks'), function() {
});
});
});
describe
(
'#removeHook'
,
function
()
{
it
(
'should remove hook'
,
function
()
{
var
hook1
=
sinon
.
spy
()
,
Model
;
Model
=
this
.
sequelize
.
define
(
'Model'
,
{
name
:
Sequelize
.
STRING
});
Model
.
addHook
(
'beforeCreate'
,
'myHook'
,
hook1
);
return
Model
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Model
.
create
({
name
:
'sonya'
});
}).
then
(
function
()
{
expect
(
hook1
.
calledOnce
).
to
.
be
.
ok
;
Model
.
removeHook
(
'beforeCreate'
,
'myHook'
);
return
Model
.
create
({
name
:
'james'
});
}).
then
(
function
()
{
expect
(
hook1
.
calledOnce
).
to
.
be
.
ok
;
});
});
});
});
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