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 3a614504
authored
Jan 18, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into milestones/2.0.0
2 parents
e7a89ad0
dbd339fb
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
4 deletions
changelog.md
lib/associations/has-many.js
lib/associations/mixin.js
lib/dao-factory.js
test/dao-factory/findAll.test.js
test/hooks.test.js
changelog.md
View file @
3a61450
...
...
@@ -5,6 +5,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
-
fixes a hangup issue for mysql
[
#1244
](
https://github.com/sequelize/sequelize/pull/1244
)
-
improves handling of uncaught errors in eventemitter
[
#1245
](
https://github.com/sequelize/sequelize/pull/1245
)
-
fixes bug with mysql replication and pool settings
[
#1251
](
https://github.com/sequelize/sequelize/pull/1251
)
-
through models created by N:M associations no longer inherit hooks
[
#1263
](
https://github.com/sequelize/sequelize/issues/1263
)
# v2.0.0 (alpha1) #
-
[
FEATURE
]
async validations.
[
#580
](
https://github.com/sequelize/sequelize/pull/580
)
. thanks to Interlock
...
...
lib/associations/has-many.js
View file @
3a61450
...
...
@@ -105,7 +105,9 @@ module.exports = (function() {
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
)
...
...
lib/associations/mixin.js
View file @
3a61450
...
...
@@ -13,7 +13,7 @@ Mixin.hasOne = function(associatedDAOFactory, options) {
options
.
useHooks
=
options
.
hooks
// 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
()
association
.
injectGetter
(
this
.
DAO
.
prototype
);
...
...
@@ -46,8 +46,10 @@ Mixin.hasMany = function(associatedDAOFactory, options) {
options
.
hooks
=
options
.
hooks
===
undefined
?
false
:
Boolean
(
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
var
association
=
new
HasMany
(
this
,
associatedDAOFactory
,
Utils
.
_
.
extend
((
options
||
{}),
this
.
options
)
)
var
association
=
new
HasMany
(
this
,
associatedDAOFactory
,
options
)
this
.
associations
[
association
.
associationAccessor
]
=
association
.
injectAttributes
()
association
.
injectGetter
(
this
.
DAO
.
prototype
)
...
...
lib/dao-factory.js
View file @
3a61450
...
...
@@ -1430,7 +1430,14 @@ module.exports = (function() {
var
optClone
=
function
(
options
)
{
return
Utils
.
_
.
cloneDeep
(
options
,
function
(
elem
)
{
// The DAOFactories used for include are pass by ref, so don't clone them. Otherwise return undefined, meaning, 'handle this lodash'
return
elem
instanceof
DAOFactory
?
elem
:
undefined
if
(
elem
instanceof
DAOFactory
)
{
return
elem
}
if
(
elem
instanceof
Utils
.
col
||
elem
instanceof
Utils
.
literal
||
elem
instanceof
Utils
.
cast
||
elem
instanceof
Utils
.
fn
)
{
return
elem
}
return
undefined
})
}
...
...
test/dao-factory/findAll.test.js
View file @
3a61450
...
...
@@ -857,6 +857,22 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
it
.
only
(
'should be possible to order by sequelize.col()'
,
function
(
done
)
{
var
self
=
this
var
Company
=
this
.
sequelize
.
define
(
'Company'
,
{
name
:
Sequelize
.
STRING
});
Company
.
sync
().
done
(
function
()
{
Company
.
findAll
({
order
:
[
self
.
sequelize
.
col
(
'name'
)]
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
done
()
})
})
})
})
})
...
...
test/hooks.test.js
View file @
3a61450
...
...
@@ -4,6 +4,8 @@ var chai = require('chai')
,
Support
=
require
(
__dirname
+
'/support'
)
,
DataTypes
=
require
(
__dirname
+
'/../lib/data-types'
)
,
_
=
require
(
'lodash'
)
,
Sequelize
=
Support
.
Sequelize
,
sinon
=
require
(
'sinon'
)
chai
.
Assertion
.
includeStack
=
true
...
...
@@ -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
()
{
...
...
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