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 696cc28e
authored
May 11, 2014
by
Overlook Motel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tidying code (no functional change)
1 parent
1fa99b9d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
18 deletions
lib/associations/has-many.js
lib/associations/has-many.js
View file @
696cc28
...
@@ -49,12 +49,15 @@ module.exports = (function() {
...
@@ -49,12 +49,15 @@ module.exports = (function() {
*/
*/
this
.
associationAccessor
=
this
.
as
this
.
associationAccessor
=
this
.
as
if
(
!
this
.
associationAccessor
&&
(
typeof
this
.
through
===
"string"
||
Object
(
this
.
through
)
===
this
.
through
))
{
if
(
!
this
.
associationAccessor
)
{
this
.
associationAccessor
=
this
.
through
.
tableName
||
this
.
through
if
(
typeof
this
.
through
===
'string'
)
{
}
this
.
associationAccessor
=
this
.
through
else
if
(
!
this
.
associationAccessor
)
{
}
else
if
(
Object
(
this
.
through
)
===
this
.
through
)
{
this
.
associationAccessor
=
this
.
through
.
tableName
}
else
{
this
.
associationAccessor
=
this
.
combinedTableName
this
.
associationAccessor
=
this
.
combinedTableName
}
}
}
/*
/*
* If self association, this is the target association - Unless we find a pairing association
* If self association, this is the target association - Unless we find a pairing association
...
@@ -69,15 +72,15 @@ module.exports = (function() {
...
@@ -69,15 +72,15 @@ module.exports = (function() {
if
(
this
.
through
)
{
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
// 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
)
{
paired
=
true
paired
=
accessor
===
self
.
associationAccessor
}
}
// 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
)
{
else
{
paired
=
true
paired
=
self
.
options
.
through
===
association
.
options
.
through
}
}
// 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
)
{
...
@@ -90,14 +93,13 @@ module.exports = (function() {
...
@@ -90,14 +93,13 @@ module.exports = (function() {
}
}
})
})
}
}
/*
/*
* If we are double linked, and through is either default or a string, we create the through model and set it on both associations
* If we are double linked, and through is either default or a string, we create the through model and set it on both associations
*/
*/
if
(
this
.
doubleLinked
)
{
if
(
this
.
doubleLinked
&&
this
.
through
===
true
)
{
if
(
this
.
through
===
true
)
{
this
.
through
=
this
.
combinedTableName
this
.
through
=
this
.
combinedTableName
}
}
}
if
(
typeof
this
.
through
===
"string"
)
{
if
(
typeof
this
.
through
===
"string"
)
{
this
.
through
=
this
.
sequelize
.
define
(
this
.
through
,
{},
_
.
extend
(
this
.
options
,
{
this
.
through
=
this
.
sequelize
.
define
(
this
.
through
,
{},
_
.
extend
(
this
.
options
,
{
...
@@ -185,8 +187,7 @@ module.exports = (function() {
...
@@ -185,8 +187,7 @@ module.exports = (function() {
})
})
// define a new model, which connects the models
// define a new model, which connects the models
var
combinedTableAttributes
=
{}
var
sourceKeyType
=
this
.
source
.
rawAttributes
[
this
.
source
.
primaryKeyAttribute
].
type
,
sourceKeyType
=
this
.
source
.
rawAttributes
[
this
.
source
.
primaryKeyAttribute
].
type
,
targetKeyType
=
this
.
target
.
rawAttributes
[
this
.
target
.
primaryKeyAttribute
].
type
,
targetKeyType
=
this
.
target
.
rawAttributes
[
this
.
target
.
primaryKeyAttribute
].
type
,
sourceAttribute
=
{
type
:
sourceKeyType
}
,
sourceAttribute
=
{
type
:
sourceKeyType
}
,
targetAttribute
=
{
type
:
targetKeyType
}
,
targetAttribute
=
{
type
:
targetKeyType
}
...
@@ -206,15 +207,11 @@ module.exports = (function() {
...
@@ -206,15 +207,11 @@ module.exports = (function() {
if
(
primaryKeyDeleted
)
{
if
(
primaryKeyDeleted
)
{
targetAttribute
.
primaryKey
=
sourceAttribute
.
primaryKey
=
true
targetAttribute
.
primaryKey
=
sourceAttribute
.
primaryKey
=
true
}
else
{
}
else
{
var
uniqueKey
=
[
this
.
through
.
tableName
,
this
.
identifier
,
this
.
foreignIdentifier
,
'unique'
].
join
(
'_'
)
var
uniqueKey
=
[
this
.
through
.
tableName
,
this
.
identifier
,
this
.
foreignIdentifier
,
'unique'
].
join
(
'_'
)
targetAttribute
.
unique
=
sourceAttribute
.
unique
=
uniqueKey
targetAttribute
.
unique
=
sourceAttribute
.
unique
=
uniqueKey
}
}
combinedTableAttributes
[
this
.
identifier
]
=
sourceAttribute
combinedTableAttributes
[
this
.
foreignIdentifier
]
=
targetAttribute
if
(
!
this
.
through
.
rawAttributes
[
this
.
identifier
])
{
if
(
!
this
.
through
.
rawAttributes
[
this
.
identifier
])
{
this
.
through
.
rawAttributes
[
this
.
identifier
]
=
{
this
.
through
.
rawAttributes
[
this
.
identifier
]
=
{
_autoGenerated
:
true
_autoGenerated
:
true
...
...
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