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 38de94a5
authored
Feb 09, 2014
by
Overlook Motel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make consistent use of as when creating associations and flag aliases
1 parent
c0092e7e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
22 deletions
lib/associations/belongs-to.js
lib/associations/has-many.js
lib/associations/has-one.js
lib/associations/belongs-to.js
View file @
38de94a
...
...
@@ -17,8 +17,10 @@ module.exports = (function() {
this
.
options
.
foreignKey
=
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
source
.
tableName
,
this
.
source
.
options
.
language
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
}
if
(
!
this
.
as
)
{
this
.
as
=
this
.
options
.
as
=
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
)
if
(
this
.
as
)
{
this
.
isAliased
=
true
}
else
{
this
.
as
=
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
)
}
this
.
associationAccessor
=
this
.
isSelfAssociation
...
...
lib/associations/has-many.js
View file @
38de94a
...
...
@@ -21,9 +21,10 @@ module.exports = (function() {
this
.
isMultiAssociation
=
true
this
.
isSelfAssociation
=
this
.
source
===
this
.
target
this
.
doubleLinked
=
false
this
.
as
=
this
.
options
.
as
this
.
combinedTableName
=
Utils
.
combineTableNames
(
this
.
source
.
tableName
,
this
.
isSelfAssociation
?
(
this
.
options
.
as
||
this
.
target
.
tableName
)
:
this
.
target
.
tableName
this
.
isSelfAssociation
?
(
this
.
as
||
this
.
target
.
tableName
)
:
this
.
target
.
tableName
)
/*
...
...
@@ -48,7 +49,7 @@ module.exports = (function() {
* Determine associationAccessor, especially for include options to identify the correct model
*/
this
.
associationAccessor
=
this
.
options
.
as
this
.
associationAccessor
=
this
.
as
if
(
!
this
.
associationAccessor
&&
(
typeof
this
.
through
===
"string"
||
Object
(
this
.
through
)
===
this
.
through
))
{
this
.
associationAccessor
=
this
.
through
.
tableName
||
this
.
through
}
...
...
@@ -112,16 +113,20 @@ module.exports = (function() {
this
.
options
.
tableName
=
this
.
combinedName
=
(
this
.
through
===
Object
(
this
.
through
)
?
this
.
through
.
tableName
:
this
.
through
)
var
as
=
(
this
.
options
.
as
||
Utils
.
pluralize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
))
if
(
this
.
as
)
{
this
.
isAliased
=
true
}
else
{
this
.
as
=
Utils
.
pluralize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
)
}
this
.
accessors
=
{
get
:
Utils
.
_
.
camelize
(
'get_'
+
as
),
set
:
Utils
.
_
.
camelize
(
'set_'
+
as
),
add
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'add_'
+
as
,
this
.
target
.
options
.
language
)),
create
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'create_'
+
as
,
this
.
target
.
options
.
language
)),
remove
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'remove_'
+
as
,
this
.
target
.
options
.
language
)),
hasSingle
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'has_'
+
as
,
this
.
target
.
options
.
language
)),
hasAll
:
Utils
.
_
.
camelize
(
'has_'
+
as
)
get
:
Utils
.
_
.
camelize
(
'get_'
+
this
.
as
),
set
:
Utils
.
_
.
camelize
(
'set_'
+
this
.
as
),
add
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'add_'
+
this
.
as
,
this
.
target
.
options
.
language
)),
create
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'create_'
+
this
.
as
,
this
.
target
.
options
.
language
)),
remove
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'remove_'
+
this
.
as
,
this
.
target
.
options
.
language
)),
hasSingle
:
Utils
.
_
.
camelize
(
Utils
.
singularize
(
'has_'
+
this
.
as
,
this
.
target
.
options
.
language
)),
hasAll
:
Utils
.
_
.
camelize
(
'has_'
+
this
.
as
)
}
}
...
...
lib/associations/has-one.js
View file @
38de94a
...
...
@@ -11,25 +11,28 @@ module.exports = (function() {
this
.
options
=
options
this
.
isSingleAssociation
=
true
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableName
)
this
.
as
=
this
.
options
.
as
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
options
.
as
)
{
this
.
options
.
foreignKey
=
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
options
.
as
,
this
.
target
.
options
.
language
)
+
"Id"
,
this
.
options
.
underscored
)
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
as
)
{
this
.
options
.
foreignKey
=
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
as
,
this
.
target
.
options
.
language
)
+
"Id"
,
this
.
options
.
underscored
)
}
if
(
!
this
.
options
.
as
)
{
this
.
options
.
as
=
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
)
if
(
this
.
as
)
{
this
.
isAliased
=
true
}
else
{
this
.
as
=
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
)
}
this
.
associationAccessor
=
this
.
isSelfAssociation
?
Utils
.
combineTableNames
(
this
.
target
.
tableName
,
this
.
options
.
as
)
:
this
.
options
.
as
?
Utils
.
combineTableNames
(
this
.
target
.
tableName
,
this
.
as
)
:
this
.
as
this
.
options
.
useHooks
=
options
.
useHooks
this
.
accessors
=
{
get
:
Utils
.
_
.
camelize
(
'get_'
+
this
.
options
.
as
),
set
:
Utils
.
_
.
camelize
(
'set_'
+
this
.
options
.
as
),
create
:
Utils
.
_
.
camelize
(
'create_'
+
this
.
options
.
as
)
get
:
Utils
.
_
.
camelize
(
'get_'
+
this
.
as
),
set
:
Utils
.
_
.
camelize
(
'set_'
+
this
.
as
),
create
:
Utils
.
_
.
camelize
(
'create_'
+
this
.
as
)
}
}
...
...
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