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 5ff5f618
authored
Feb 26, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use Model.name and not Model.tableName for association aliases and foreignkeys
1 parent
d480d382
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
14 deletions
lib/associations/belongs-to.js
lib/associations/has-many.js
lib/associations/has-one.js
lib/associations/belongs-to.js
View file @
5ff5f61
...
@@ -10,7 +10,7 @@ module.exports = (function() {
...
@@ -10,7 +10,7 @@ module.exports = (function() {
this
.
target
=
target
this
.
target
=
target
this
.
options
=
options
this
.
options
=
options
this
.
isSingleAssociation
=
true
this
.
isSingleAssociation
=
true
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableN
ame
)
this
.
isSelfAssociation
=
(
this
.
source
.
name
==
this
.
target
.
n
ame
)
this
.
as
=
this
.
options
.
as
this
.
as
=
this
.
options
.
as
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
as
)
{
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
as
)
{
...
@@ -20,15 +20,11 @@ module.exports = (function() {
...
@@ -20,15 +20,11 @@ module.exports = (function() {
if
(
this
.
as
)
{
if
(
this
.
as
)
{
this
.
isAliased
=
true
this
.
isAliased
=
true
}
else
{
}
else
{
this
.
as
=
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
)
// Hotfix
if
(
this
.
as
===
this
.
target
.
tableName
)
{
this
.
as
=
Utils
.
singularize
(
this
.
target
.
name
,
this
.
target
.
options
.
language
)
this
.
as
=
Utils
.
singularize
(
this
.
target
.
name
,
this
.
target
.
options
.
language
)
}
}
}
this
.
associationAccessor
=
this
.
isSelfAssociation
this
.
associationAccessor
=
this
.
isSelfAssociation
?
Utils
.
combineTableNames
(
this
.
target
.
tableN
ame
,
this
.
as
)
?
Utils
.
combineTableNames
(
this
.
target
.
n
ame
,
this
.
as
)
:
this
.
as
:
this
.
as
this
.
options
.
useHooks
=
options
.
useHooks
this
.
options
.
useHooks
=
options
.
useHooks
...
@@ -46,7 +42,7 @@ module.exports = (function() {
...
@@ -46,7 +42,7 @@ module.exports = (function() {
,
targetKeys
=
Object
.
keys
(
this
.
target
.
primaryKeys
)
,
targetKeys
=
Object
.
keys
(
this
.
target
.
primaryKeys
)
,
keyType
=
((
this
.
target
.
hasPrimaryKeys
&&
targetKeys
.
length
===
1
)
?
this
.
target
.
rawAttributes
[
targetKeys
[
0
]].
type
:
DataTypes
.
INTEGER
)
,
keyType
=
((
this
.
target
.
hasPrimaryKeys
&&
targetKeys
.
length
===
1
)
?
this
.
target
.
rawAttributes
[
targetKeys
[
0
]].
type
:
DataTypes
.
INTEGER
)
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
target
.
tableN
ame
,
this
.
target
.
options
.
language
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
target
.
n
ame
,
this
.
target
.
options
.
language
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
newAttributes
[
this
.
identifier
]
=
{
type
:
this
.
options
.
keyType
||
keyType
}
newAttributes
[
this
.
identifier
]
=
{
type
:
this
.
options
.
keyType
||
keyType
}
Helpers
.
addForeignKeyConstraints
(
newAttributes
[
this
.
identifier
],
this
.
target
,
this
.
source
,
this
.
options
)
Helpers
.
addForeignKeyConstraints
(
newAttributes
[
this
.
identifier
],
this
.
target
,
this
.
source
,
this
.
options
)
...
...
lib/associations/has-many.js
View file @
5ff5f61
...
@@ -116,7 +116,7 @@ module.exports = (function() {
...
@@ -116,7 +116,7 @@ module.exports = (function() {
if
(
this
.
as
)
{
if
(
this
.
as
)
{
this
.
isAliased
=
true
this
.
isAliased
=
true
}
else
{
}
else
{
this
.
as
=
Utils
.
pluralize
(
this
.
target
.
tableN
ame
,
this
.
target
.
options
.
language
)
this
.
as
=
Utils
.
pluralize
(
this
.
target
.
n
ame
,
this
.
target
.
options
.
language
)
}
}
this
.
accessors
=
{
this
.
accessors
=
{
...
@@ -137,14 +137,14 @@ module.exports = (function() {
...
@@ -137,14 +137,14 @@ module.exports = (function() {
,
self
=
this
,
self
=
this
,
primaryKeyDeleted
=
false
,
primaryKeyDeleted
=
false
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
source
.
tableN
ame
,
this
.
source
.
options
.
language
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
source
.
n
ame
,
this
.
source
.
options
.
language
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
// 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
&&
Object
(
this
.
through
)
===
this
.
through
)
||
doubleLinked
)
{
if
((
this
.
isSelfAssociation
&&
Object
(
this
.
through
)
===
this
.
through
)
||
doubleLinked
)
{
// 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
.
tableN
ame
)
+
'Id'
,
this
.
target
.
options
.
underscored
)
this
.
foreignIdentifier
=
Utils
.
_
.
underscoredIf
((
this
.
options
.
as
||
this
.
target
.
n
ame
)
+
'Id'
,
this
.
target
.
options
.
underscored
)
}
else
{
}
else
{
this
.
foreignIdentifier
=
this
.
targetAssociation
.
identifier
this
.
foreignIdentifier
=
this
.
targetAssociation
.
identifier
this
.
targetAssociation
.
foreignIdentifier
=
this
.
identifier
this
.
targetAssociation
.
foreignIdentifier
=
this
.
identifier
...
...
lib/associations/has-one.js
View file @
5ff5f61
...
@@ -10,7 +10,7 @@ module.exports = (function() {
...
@@ -10,7 +10,7 @@ module.exports = (function() {
this
.
target
=
targetDAO
this
.
target
=
targetDAO
this
.
options
=
options
this
.
options
=
options
this
.
isSingleAssociation
=
true
this
.
isSingleAssociation
=
true
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableN
ame
)
this
.
isSelfAssociation
=
(
this
.
source
.
name
==
this
.
target
.
n
ame
)
this
.
as
=
this
.
options
.
as
this
.
as
=
this
.
options
.
as
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
as
)
{
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
as
)
{
...
@@ -20,11 +20,11 @@ module.exports = (function() {
...
@@ -20,11 +20,11 @@ module.exports = (function() {
if
(
this
.
as
)
{
if
(
this
.
as
)
{
this
.
isAliased
=
true
this
.
isAliased
=
true
}
else
{
}
else
{
this
.
as
=
Utils
.
singularize
(
this
.
target
.
tableN
ame
,
this
.
target
.
options
.
language
)
this
.
as
=
Utils
.
singularize
(
this
.
target
.
n
ame
,
this
.
target
.
options
.
language
)
}
}
this
.
associationAccessor
=
this
.
isSelfAssociation
this
.
associationAccessor
=
this
.
isSelfAssociation
?
Utils
.
combineTableNames
(
this
.
target
.
tableN
ame
,
this
.
as
)
?
Utils
.
combineTableNames
(
this
.
target
.
n
ame
,
this
.
as
)
:
this
.
as
:
this
.
as
this
.
options
.
useHooks
=
options
.
useHooks
this
.
options
.
useHooks
=
options
.
useHooks
...
@@ -42,7 +42,7 @@ module.exports = (function() {
...
@@ -42,7 +42,7 @@ module.exports = (function() {
,
sourceKeys
=
Object
.
keys
(
this
.
source
.
primaryKeys
)
,
sourceKeys
=
Object
.
keys
(
this
.
source
.
primaryKeys
)
,
keyType
=
((
this
.
source
.
hasPrimaryKeys
&&
sourceKeys
.
length
===
1
)
?
this
.
source
.
rawAttributes
[
sourceKeys
[
0
]].
type
:
DataTypes
.
INTEGER
)
,
keyType
=
((
this
.
source
.
hasPrimaryKeys
&&
sourceKeys
.
length
===
1
)
?
this
.
source
.
rawAttributes
[
sourceKeys
[
0
]].
type
:
DataTypes
.
INTEGER
)
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
source
.
tableN
ame
,
this
.
source
.
options
.
language
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
source
.
n
ame
,
this
.
source
.
options
.
language
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
newAttributes
[
this
.
identifier
]
=
{
type
:
this
.
options
.
keyType
||
keyType
}
newAttributes
[
this
.
identifier
]
=
{
type
:
this
.
options
.
keyType
||
keyType
}
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
Helpers
.
addForeignKeyConstraints
(
this
.
target
.
rawAttributes
[
this
.
identifier
],
this
.
source
,
this
.
target
,
this
.
options
)
Helpers
.
addForeignKeyConstraints
(
this
.
target
.
rawAttributes
[
this
.
identifier
],
this
.
source
,
this
.
target
,
this
.
options
)
...
...
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