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 751da171
authored
Jan 18, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not pass hooks option on to through model, fixes #1263
1 parent
fea739d8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
3 deletions
lib/associations/has-many.js
lib/associations/mixin.js
test/hooks.test.js
lib/associations/has-many.js
View file @
751da17
...
@@ -105,7 +105,9 @@ module.exports = (function() {
...
@@ -105,7 +105,9 @@ module.exports = (function() {
tableName
:
this
.
through
tableName
:
this
.
through
}))
}))
if
(
this
.
targetAssociation
)
this
.
targetAssociation
.
through
=
this
.
through
if
(
this
.
targetAssociation
)
{
this
.
targetAssociation
.
through
=
this
.
through
}
}
}
this
.
options
.
tableName
=
this
.
combinedName
=
(
this
.
through
===
Object
(
this
.
through
)
?
this
.
through
.
tableName
:
this
.
through
)
this
.
options
.
tableName
=
this
.
combinedName
=
(
this
.
through
===
Object
(
this
.
through
)
?
this
.
through
.
tableName
:
this
.
through
)
...
...
lib/associations/mixin.js
View file @
751da17
...
@@ -13,7 +13,7 @@ Mixin.hasOne = function(associatedDAOFactory, options) {
...
@@ -13,7 +13,7 @@ Mixin.hasOne = function(associatedDAOFactory, options) {
options
.
useHooks
=
options
.
hooks
options
.
useHooks
=
options
.
hooks
// the id is in the foreign table
// the id is in the foreign table
var
association
=
new
HasOne
(
this
,
associatedDAOFactory
,
Utils
.
_
.
extend
(
(
options
||
{})
,
this
.
options
))
var
association
=
new
HasOne
(
this
,
associatedDAOFactory
,
Utils
.
_
.
extend
(
options
,
this
.
options
))
this
.
associations
[
association
.
associationAccessor
]
=
association
.
injectAttributes
()
this
.
associations
[
association
.
associationAccessor
]
=
association
.
injectAttributes
()
association
.
injectGetter
(
this
.
DAO
.
prototype
);
association
.
injectGetter
(
this
.
DAO
.
prototype
);
...
@@ -46,8 +46,10 @@ Mixin.hasMany = function(associatedDAOFactory, options) {
...
@@ -46,8 +46,10 @@ Mixin.hasMany = function(associatedDAOFactory, options) {
options
.
hooks
=
options
.
hooks
===
undefined
?
false
:
Boolean
(
options
.
hooks
)
options
.
hooks
=
options
.
hooks
===
undefined
?
false
:
Boolean
(
options
.
hooks
)
options
.
useHooks
=
options
.
hooks
options
.
useHooks
=
options
.
hooks
options
=
Utils
.
_
.
extend
(
options
,
Utils
.
_
.
omit
(
this
.
options
,
[
'hooks'
]))
// the id is in the foreign table or in a connecting table
// the id is in the foreign table or in a connecting table
var
association
=
new
HasMany
(
this
,
associatedDAOFactory
,
Utils
.
_
.
extend
((
options
||
{}),
this
.
options
)
)
var
association
=
new
HasMany
(
this
,
associatedDAOFactory
,
options
)
this
.
associations
[
association
.
associationAccessor
]
=
association
.
injectAttributes
()
this
.
associations
[
association
.
associationAccessor
]
=
association
.
injectAttributes
()
association
.
injectGetter
(
this
.
DAO
.
prototype
)
association
.
injectGetter
(
this
.
DAO
.
prototype
)
...
...
test/hooks.test.js
View file @
751da17
...
@@ -4,6 +4,8 @@ var chai = require('chai')
...
@@ -4,6 +4,8 @@ var chai = require('chai')
,
Support
=
require
(
__dirname
+
'/support'
)
,
Support
=
require
(
__dirname
+
'/support'
)
,
DataTypes
=
require
(
__dirname
+
'/../lib/data-types'
)
,
DataTypes
=
require
(
__dirname
+
'/../lib/data-types'
)
,
_
=
require
(
'lodash'
)
,
_
=
require
(
'lodash'
)
,
Sequelize
=
Support
.
Sequelize
,
sinon
=
require
(
'sinon'
)
chai
.
Assertion
.
includeStack
=
true
chai
.
Assertion
.
includeStack
=
true
...
@@ -1866,6 +1868,43 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
...
@@ -1866,6 +1868,43 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
})
})
})
})
})
})
it
(
'should not trigger hooks on parent when using N:M association setters'
,
function
(
done
)
{
var
A
=
this
.
sequelize
.
define
(
'A'
,
{
name
:
Sequelize
.
STRING
})
var
B
=
this
.
sequelize
.
define
(
'B'
,
{
name
:
Sequelize
.
STRING
})
var
hookCalled
=
0
A
.
addHook
(
'afterCreate'
,
function
(
instance
,
next
)
{
hookCalled
++
next
()
})
B
.
hasMany
(
A
)
A
.
hasMany
(
B
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
A
.
create
({
name
:
'a'
}),
B
.
create
({
name
:
'b'
})
])
chainer
.
run
().
done
(
function
(
err
,
res
,
a
,
b
)
{
expect
(
err
).
not
.
to
.
be
.
ok
a
.
addB
(
b
).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
hookCalled
).
to
.
equal
(
1
)
done
()
})
})
})
})
})
})
describe
(
'#updateAttributes'
,
function
()
{
describe
(
'#updateAttributes'
,
function
()
{
...
...
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