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 0e4c7a60
authored
Feb 24, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(hooks): normalize Model.hooks to arrays (if a user passed a single method it…
… failed), closes #3179
1 parent
03612872
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
4 deletions
lib/hooks.js
lib/model.js
test/integration/hooks.test.js
lib/hooks.js
View file @
0e4c7a6
...
...
@@ -152,12 +152,10 @@ Hooks.addHook = function(hookType, name, fn) {
name
=
null
;
}
// Aliases
hookType
=
hookAliases
[
hookType
]
||
hookType
;
// Just in case if we override the default DAOFactory.options
this
.
options
.
hooks
[
hookType
]
=
this
.
options
.
hooks
[
hookType
]
||
[];
this
.
options
.
hooks
[
hookType
]
[
this
.
options
.
hooks
[
hookType
].
length
]
=
!!
name
?
{
name
:
name
,
fn
:
fn
}
:
fn
;
this
.
options
.
hooks
[
hookType
]
.
push
(
!!
name
?
{
name
:
name
,
fn
:
fn
}
:
fn
)
;
return
this
;
};
...
...
lib/model.js
View file @
0e4c7a6
...
...
@@ -46,7 +46,11 @@ module.exports = (function() {
this
.
associations
=
{};
this
.
modelManager
=
this
.
daoFactoryManager
=
null
;
this
.
name
=
name
;
this
.
options
.
hooks
=
this
.
replaceHookAliases
(
this
.
options
.
hooks
);
this
.
options
.
hooks
=
_
.
mapValues
(
this
.
replaceHookAliases
(
this
.
options
.
hooks
),
function
(
hooks
)
{
if
(
!
Array
.
isArray
(
hooks
))
hooks
=
[
hooks
];
return
hooks
;
});
this
.
scopeObj
=
{};
this
.
sequelize
=
options
.
sequelize
;
this
.
underscored
=
this
.
underscored
||
this
.
underscoredAll
;
...
...
test/integration/hooks.test.js
View file @
0e4c7a6
...
...
@@ -5877,4 +5877,27 @@ describe(Support.getTestDialectTeaser('Hooks'), function() {
});
});
});
describe
(
'#addHook'
,
function
()
{
it
(
'should add additinoal hook when previous exists'
,
function
()
{
var
hook1
=
sinon
.
spy
()
,
hook2
=
sinon
.
spy
()
,
Model
;
Model
=
this
.
sequelize
.
define
(
'Model'
,
{
name
:
Sequelize
.
STRING
},
{
hooks
:
{
beforeCreate
:
hook1
}
});
Model
.
addHook
(
'beforeCreate'
,
hook2
);
return
Model
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Model
.
create
({
name
:
'bob'
});
}).
then
(
function
()
{
expect
(
hook1
.
calledOnce
).
to
.
be
.
ok
;
expect
(
hook2
.
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