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 d051e804
authored
Dec 19, 2013
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final refactoring
1 parent
630d203f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
16 deletions
lib/associations/has-many-double-linked.js
lib/associations/has-many.js
lib/dialects/abstract/query-generator.js
test/associations/has-many.test.js
lib/associations/has-many-double-linked.js
View file @
d051e80
...
@@ -36,7 +36,7 @@ module.exports = (function() {
...
@@ -36,7 +36,7 @@ module.exports = (function() {
where
[
through
.
tableName
+
"."
+
foreignKey
]
=
{
join
:
self
.
__factory
.
target
.
tableName
+
"."
+
foreignPrimary
}
where
[
through
.
tableName
+
"."
+
foreignKey
]
=
{
join
:
self
.
__factory
.
target
.
tableName
+
"."
+
foreignPrimary
}
if
(
association
.
hasJoinTableModel
)
{
if
(
Object
(
association
.
through
)
===
association
.
through
)
{
queryOptions
.
hasJoinTableModel
=
true
queryOptions
.
hasJoinTableModel
=
true
queryOptions
.
joinTableModel
=
through
queryOptions
.
joinTableModel
=
through
...
@@ -102,8 +102,6 @@ module.exports = (function() {
...
@@ -102,8 +102,6 @@ module.exports = (function() {
,
options
=
{}
,
options
=
{}
,
unassociatedObjects
;
,
unassociatedObjects
;
console
.
log
(
":D"
)
if
((
defaultAttributes
||
{}).
transaction
instanceof
Transaction
)
{
if
((
defaultAttributes
||
{}).
transaction
instanceof
Transaction
)
{
options
.
transaction
=
defaultAttributes
.
transaction
options
.
transaction
=
defaultAttributes
.
transaction
delete
defaultAttributes
.
transaction
delete
defaultAttributes
.
transaction
...
@@ -155,7 +153,7 @@ module.exports = (function() {
...
@@ -155,7 +153,7 @@ module.exports = (function() {
attributes
[
self
.
__factory
.
identifier
]
=
((
sourceKeys
.
length
===
1
)
?
self
.
instance
[
sourceKeys
[
0
]]
:
self
.
instance
.
id
)
attributes
[
self
.
__factory
.
identifier
]
=
((
sourceKeys
.
length
===
1
)
?
self
.
instance
[
sourceKeys
[
0
]]
:
self
.
instance
.
id
)
attributes
[
foreignIdentifier
]
=
((
targetKeys
.
length
===
1
)
?
unassociatedObject
[
targetKeys
[
0
]]
:
unassociatedObject
.
id
)
attributes
[
foreignIdentifier
]
=
((
targetKeys
.
length
===
1
)
?
unassociatedObject
[
targetKeys
[
0
]]
:
unassociatedObject
.
id
)
if
(
association
.
hasJoinTableModel
)
{
if
(
Object
(
association
.
through
)
===
association
.
through
)
{
attributes
=
Utils
.
_
.
defaults
(
attributes
,
unassociatedObject
[
association
.
through
.
name
],
defaultAttributes
)
attributes
=
Utils
.
_
.
defaults
(
attributes
,
unassociatedObject
[
association
.
through
.
name
],
defaultAttributes
)
}
}
...
...
lib/associations/has-many.js
View file @
d051e80
var
Utils
=
require
(
"./../utils"
)
var
Utils
=
require
(
"./../utils"
)
,
DataTypes
=
require
(
'./../data-types'
)
,
DataTypes
=
require
(
'./../data-types'
)
,
Helpers
=
require
(
'./helpers'
)
,
Helpers
=
require
(
'./helpers'
)
,
_
=
require
(
'lodash'
)
var
HasManySingleLinked
=
require
(
"./has-many-single-linked"
)
var
HasManySingleLinked
=
require
(
"./has-many-single-linked"
)
,
HasManyMultiLinked
=
require
(
"./has-many-double-linked"
)
,
HasManyMultiLinked
=
require
(
"./has-many-double-linked"
)
...
@@ -18,9 +19,13 @@ module.exports = (function() {
...
@@ -18,9 +19,13 @@ module.exports = (function() {
if
(
this
.
through
===
undefined
)
{
if
(
this
.
through
===
undefined
)
{
this
.
through
=
this
.
options
.
joinTableModel
||
this
.
options
.
joinTableName
;
this
.
through
=
this
.
options
.
joinTableModel
||
this
.
options
.
joinTableName
;
}
}
if
(
typeof
this
.
through
===
"string"
)
{
if
(
typeof
this
.
through
===
"string"
)
{
this
.
through
=
this
.
source
.
daoFactoryManager
.
sequelize
.
define
(
this
.
through
,
{},
this
.
options
)
this
.
through
=
this
.
source
.
daoFactoryManager
.
sequelize
.
define
(
this
.
through
,
{},
_
.
extend
(
this
.
options
,
{
tableName
:
this
.
through
}))
}
}
if
(
this
.
through
===
undefined
)
{
if
(
this
.
through
===
undefined
)
{
if
(
this
.
options
.
useJunctionTable
===
false
)
{
if
(
this
.
options
.
useJunctionTable
===
false
)
{
this
.
through
=
null
;
this
.
through
=
null
;
...
@@ -61,7 +66,7 @@ module.exports = (function() {
...
@@ -61,7 +66,7 @@ module.exports = (function() {
// is there already a single sided association between the source and the target?
// is there already a single sided association between the source and the target?
// or is the association on the model itself?
// or is the association on the model itself?
if
((
this
.
isSelfAssociation
&&
this
.
useJunctionTable
)
||
multiAssociation
)
{
if
((
this
.
isSelfAssociation
&&
this
.
through
)
||
multiAssociation
)
{
// remove the obsolete association identifier from the source
// remove the obsolete association identifier from the source
if
(
this
.
isSelfAssociation
)
{
if
(
this
.
isSelfAssociation
)
{
this
.
foreignIdentifier
=
Utils
.
_
.
underscoredIf
((
this
.
options
.
as
||
this
.
target
.
tableName
)
+
'Id'
,
this
.
options
.
underscored
)
this
.
foreignIdentifier
=
Utils
.
_
.
underscoredIf
((
this
.
options
.
as
||
this
.
target
.
tableName
)
+
'Id'
,
this
.
options
.
underscored
)
...
@@ -115,8 +120,6 @@ module.exports = (function() {
...
@@ -115,8 +120,6 @@ module.exports = (function() {
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
}
}
this
.
connectorDAO
=
Object
(
this
.
through
)
===
this
.
through
?
this
.
through
:
null
;
// Lets not break EVERYTHING just yet
// Sync attributes and setters/getters to DAO prototype
// Sync attributes and setters/getters to DAO prototype
this
.
target
.
refreshAttributes
()
this
.
target
.
refreshAttributes
()
this
.
source
.
refreshAttributes
()
this
.
source
.
refreshAttributes
()
...
...
lib/dialects/abstract/query-generator.js
View file @
d051e80
...
@@ -635,14 +635,14 @@ module.exports = (function() {
...
@@ -635,14 +635,14 @@ module.exports = (function() {
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
identifier
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
identifier
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
+
'.'
+
association
.
target
.
autoIncrementField
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
+
'.'
+
association
.
target
.
autoIncrementField
)
}
else
if
(
association
.
connectorDAO
)
{
}
else
if
(
Object
(
association
.
through
)
===
association
.
through
)
{
joinedTables
[
association
.
connectorDAO
.
tableName
]
=
true
;
joinedTables
[
association
.
through
.
tableName
]
=
true
;
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
connectorDAO
.
tableName
)
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
through
.
tableName
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
source
.
autoIncrementField
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
source
.
tableName
+
'.'
+
association
.
source
.
autoIncrementField
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
connectorDAO
.
tableName
+
'.'
+
association
.
identifier
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
through
.
tableName
+
'.'
+
association
.
identifier
)
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
connectorDAO
.
tableName
+
'.'
+
association
.
foreignIdentifier
)
joins
+=
' ON '
+
self
.
quoteIdentifiers
(
association
.
through
.
tableName
+
'.'
+
association
.
foreignIdentifier
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
+
'.'
+
association
.
target
.
autoIncrementField
)
joins
+=
' = '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
+
'.'
+
association
.
target
.
autoIncrementField
)
}
else
{
}
else
{
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
joins
+=
' LEFT JOIN '
+
self
.
quoteIdentifiers
(
association
.
target
.
tableName
)
...
...
test/associations/has-many.test.js
View file @
d051e80
...
@@ -693,9 +693,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -693,9 +693,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect
(
associationName
).
not
.
to
.
equal
(
this
.
User
.
tableName
)
expect
(
associationName
).
not
.
to
.
equal
(
this
.
User
.
tableName
)
expect
(
associationName
).
not
.
to
.
equal
(
this
.
Task
.
tableName
)
expect
(
associationName
).
not
.
to
.
equal
(
this
.
Task
.
tableName
)
var
joinTableName
=
this
.
User
.
associations
[
associationName
].
options
.
joinTableName
var
through
=
this
.
User
.
associations
[
associationName
].
through
if
(
typeof
joinTableName
!==
'undefined'
)
{
if
(
typeof
through
!==
'undefined'
)
{
expect
(
joinT
ableName
).
to
.
equal
(
associationName
)
expect
(
through
.
t
ableName
).
to
.
equal
(
associationName
)
}
}
var
tableName
=
this
.
User
.
associations
[
associationName
].
options
.
tableName
var
tableName
=
this
.
User
.
associations
[
associationName
].
options
.
tableName
if
(
typeof
tableName
!==
'undefined'
)
{
if
(
typeof
tableName
!==
'undefined'
)
{
...
...
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