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
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
23 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
...
@@ -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
)
-
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
)
-
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
)
-
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) #
# v2.0.0 (alpha1) #
-
[
FEATURE
]
async validations.
[
#580
](
https://github.com/sequelize/sequelize/pull/580
)
. thanks to Interlock
-
[
FEATURE
]
async validations.
[
#580
](
https://github.com/sequelize/sequelize/pull/580
)
. thanks to Interlock
...
...
lib/associations/has-many.js
View file @
3a61450
...
@@ -67,28 +67,28 @@ module.exports = (function() {
...
@@ -67,28 +67,28 @@ module.exports = (function() {
* Else find partner DAOFactory if present, to identify double linked association
* Else find partner DAOFactory if present, to identify double linked association
*/
*/
else
if
(
this
.
through
)
{
else
if
(
this
.
through
)
{
_
.
each
(
this
.
target
.
associations
,
function
(
association
,
accessor
)
{
_
.
each
(
this
.
target
.
associations
,
function
(
association
,
accessor
)
{
if
(
self
.
source
===
association
.
target
)
{
if
(
self
.
source
===
association
.
target
)
{
var
paired
=
false
var
paired
=
false
// If through is default, we determine pairing by the accesor value (i.e. DAOFactory's using as won't pair, but regular ones will)
// If through is default, we determine pairing by the accesor value (i.e. DAOFactory's using as won't pair, but regular ones will)
if
(
self
.
through
===
true
&&
accessor
===
self
.
associationAccessor
)
{
if
(
self
.
through
===
true
&&
accessor
===
self
.
associationAccessor
)
{
paired
=
true
paired
=
true
}
}
// If through is not default, determine pairing by through value (model/string)
// If through is not default, determine pairing by through value (model/string)
if
(
self
.
through
!==
true
&&
self
.
options
.
through
===
association
.
options
.
through
)
{
if
(
self
.
through
!==
true
&&
self
.
options
.
through
===
association
.
options
.
through
)
{
paired
=
true
paired
=
true
}
}
// If paired, set properties identifying both associations as double linked, and allow them to each eachtoerh
// If paired, set properties identifying both associations as double linked, and allow them to each eachtoerh
if
(
paired
)
{
if
(
paired
)
{
self
.
doubleLinked
=
true
self
.
doubleLinked
=
true
association
.
doubleLinked
=
true
association
.
doubleLinked
=
true
self
.
targetAssociation
=
association
self
.
targetAssociation
=
association
association
.
targetAssociation
=
self
association
.
targetAssociation
=
self
}
}
}
}
})
})
}
}
/*
/*
...
@@ -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 @
3a61450
...
@@ -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
)
...
...
lib/dao-factory.js
View file @
3a61450
...
@@ -1430,7 +1430,14 @@ module.exports = (function() {
...
@@ -1430,7 +1430,14 @@ module.exports = (function() {
var
optClone
=
function
(
options
)
{
var
optClone
=
function
(
options
)
{
return
Utils
.
_
.
cloneDeep
(
options
,
function
(
elem
)
{
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'
// 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 () {
...
@@ -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')
...
@@ -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