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 d8cfd984
authored
Nov 10, 2011
by
Meg Sharkey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow association table name to be specified, pass through freeze table name and underscore options
1 parent
1bf57680
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
3 deletions
lib/sequelize/associations/has-many.js
spec/associations.spec.js
lib/sequelize/associations/has-many.js
View file @
d8cfd98
...
@@ -10,7 +10,7 @@ var HasMany = module.exports = function(srcModel, targetModel, options) {
...
@@ -10,7 +10,7 @@ var HasMany = module.exports = function(srcModel, targetModel, options) {
this
.
options
=
options
this
.
options
=
options
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableName
)
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableName
)
this
.
associationAccessor
=
this
.
combinedName
=
Utils
.
combineTableNames
(
this
.
associationAccessor
=
this
.
combinedName
=
this
.
options
.
joinTableName
||
Utils
.
combineTableNames
(
this
.
source
.
tableName
,
this
.
source
.
tableName
,
this
.
isSelfAssociation
?
(
this
.
options
.
as
||
this
.
target
.
tableName
)
:
this
.
target
.
tableName
this
.
isSelfAssociation
?
(
this
.
options
.
as
||
this
.
target
.
tableName
)
:
this
.
target
.
tableName
)
)
...
@@ -36,7 +36,7 @@ HasMany.prototype.injectAttributes = function() {
...
@@ -36,7 +36,7 @@ HasMany.prototype.injectAttributes = function() {
if
(
this
.
isSelfAssociation
||
multiAssociation
)
{
if
(
this
.
isSelfAssociation
||
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
=
(
this
.
options
.
as
||
this
.
target
.
tableName
)
+
'Id'
this
.
foreignIdentifier
=
Utils
.
_
.
underscoredIf
((
this
.
options
.
as
||
this
.
target
.
tableName
)
+
'Id'
,
this
.
options
.
underscored
)
}
else
{
}
else
{
this
.
foreignIdentifier
=
this
.
target
.
associations
[
this
.
associationAccessor
].
identifier
this
.
foreignIdentifier
=
this
.
target
.
associations
[
this
.
associationAccessor
].
identifier
delete
this
.
source
.
attributes
[
this
.
foreignIdentifier
]
delete
this
.
source
.
attributes
[
this
.
foreignIdentifier
]
...
@@ -47,7 +47,7 @@ HasMany.prototype.injectAttributes = function() {
...
@@ -47,7 +47,7 @@ HasMany.prototype.injectAttributes = function() {
combinedTableAttributes
[
this
.
identifier
]
=
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
}
combinedTableAttributes
[
this
.
identifier
]
=
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
}
combinedTableAttributes
[
this
.
foreignIdentifier
]
=
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
}
combinedTableAttributes
[
this
.
foreignIdentifier
]
=
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
}
this
.
connectorModel
=
this
.
source
.
modelManager
.
sequelize
.
define
(
this
.
combinedName
,
combinedTableAttributes
)
this
.
connectorModel
=
this
.
source
.
modelManager
.
sequelize
.
define
(
this
.
combinedName
,
combinedTableAttributes
,
this
.
options
)
if
(
!
this
.
isSelfAssociation
)
this
.
target
.
associations
[
this
.
associationAccessor
].
connectorModel
=
this
.
connectorModel
if
(
!
this
.
isSelfAssociation
)
this
.
target
.
associations
[
this
.
associationAccessor
].
connectorModel
=
this
.
connectorModel
this
.
connectorModel
.
sync
()
this
.
connectorModel
.
sync
()
...
...
spec/associations.spec.js
View file @
d8cfd98
...
@@ -21,6 +21,7 @@ describe('Associations', function() {
...
@@ -21,6 +21,7 @@ describe('Associations', function() {
expect
(
sequelize
.
modelManager
.
getModel
(
'wp_table1swp_table2s'
)).
toBeDefined
()
expect
(
sequelize
.
modelManager
.
getModel
(
'wp_table1swp_table2s'
)).
toBeDefined
()
})
})
})
})
// TODO add test for specifying join table name
})
})
})
})
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