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 b98d94f4
authored
May 09, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed combinedName to associationAccessors
1 parent
7aebe2c6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
10 deletions
lib/sequelize/associations/has-many-double-linked.js
lib/sequelize/associations/has-many.js
lib/sequelize/associations/mixin.js
lib/sequelize/associations/has-many-double-linked.js
View file @
b98d94f
...
@@ -36,7 +36,7 @@ HasManyDoubleLinked.prototype.destroyObsoleteAssociations = function(oldAssociat
...
@@ -36,7 +36,7 @@ HasManyDoubleLinked.prototype.destroyObsoleteAssociations = function(oldAssociat
var
emitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
var
emitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
var
chainer
=
new
Utils
.
QueryChainer
var
chainer
=
new
Utils
.
QueryChainer
var
foreignIdentifier
=
self
.
definition
.
target
.
associations
[
self
.
definition
.
combinedName
].
identifier
var
foreignIdentifier
=
self
.
definition
.
target
.
associations
[
self
.
definition
.
associationAccessor
].
identifier
var
obsoleteAssociations
=
oldAssociations
.
filter
(
function
(
obj
)
{
return
!
obj
.
equalsOneOf
(
newAssociations
)
})
var
obsoleteAssociations
=
oldAssociations
.
filter
(
function
(
obj
)
{
return
!
obj
.
equalsOneOf
(
newAssociations
)
})
if
(
obsoleteAssociations
.
length
==
0
)
if
(
obsoleteAssociations
.
length
==
0
)
...
@@ -73,7 +73,7 @@ HasManyDoubleLinked.prototype.injectSetter = function(emitter, oldAssociations,
...
@@ -73,7 +73,7 @@ HasManyDoubleLinked.prototype.injectSetter = function(emitter, oldAssociations,
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'success'
,
function
()
{
.
on
(
'success'
,
function
()
{
var
chainer
=
new
Utils
.
QueryChainer
var
chainer
=
new
Utils
.
QueryChainer
,
association
=
self
.
definition
.
target
.
associations
[
self
.
definition
.
combinedName
]
,
association
=
self
.
definition
.
target
.
associations
[
self
.
definition
.
associationAccessor
]
,
foreignIdentifier
=
association
.
isSelfAssociation
?
association
.
foreignIdentifier
:
association
.
identifier
,
foreignIdentifier
=
association
.
isSelfAssociation
?
association
.
foreignIdentifier
:
association
.
identifier
,
unassociatedObjects
=
newAssociations
.
filter
(
function
(
obj
)
{
return
!
obj
.
equalsOneOf
(
oldAssociations
)
})
,
unassociatedObjects
=
newAssociations
.
filter
(
function
(
obj
)
{
return
!
obj
.
equalsOneOf
(
oldAssociations
)
})
...
...
lib/sequelize/associations/has-many.js
View file @
b98d94f
...
@@ -9,12 +9,12 @@ var HasMany = module.exports = function(srcModel, targetModel, options) {
...
@@ -9,12 +9,12 @@ var HasMany = module.exports = function(srcModel, targetModel, options) {
this
.
target
=
targetModel
this
.
target
=
targetModel
this
.
options
=
options
this
.
options
=
options
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableName
)
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableName
)
this
.
combinedName
=
Utils
.
combineTableNames
(
this
.
associationAccessor
=
this
.
combinedName
=
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
)
)
var
as
=
(
this
.
options
.
as
||
Utils
.
pluralize
(
this
.
target
.
tableName
))
var
as
=
(
this
.
options
.
as
||
Utils
.
pluralize
(
this
.
target
.
tableName
))
this
.
accessors
=
{
this
.
accessors
=
{
...
@@ -28,7 +28,7 @@ var HasMany = module.exports = function(srcModel, targetModel, options) {
...
@@ -28,7 +28,7 @@ var HasMany = module.exports = function(srcModel, targetModel, options) {
// the id is in the target table
// the id is in the target table
// or in an extra table which connects two tables
// or in an extra table which connects two tables
HasMany
.
prototype
.
injectAttributes
=
function
()
{
HasMany
.
prototype
.
injectAttributes
=
function
()
{
var
multiAssociation
=
this
.
target
.
associations
.
hasOwnProperty
(
this
.
combinedName
)
var
multiAssociation
=
this
.
target
.
associations
.
hasOwnProperty
(
this
.
associationAccessor
)
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
source
.
tableName
)
+
"Id"
,
this
.
options
.
underscored
)
this
.
identifier
=
this
.
options
.
foreignKey
||
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
source
.
tableName
)
+
"Id"
,
this
.
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?
...
@@ -38,7 +38,7 @@ HasMany.prototype.injectAttributes = function() {
...
@@ -38,7 +38,7 @@ HasMany.prototype.injectAttributes = function() {
if
(
this
.
isSelfAssociation
)
{
if
(
this
.
isSelfAssociation
)
{
this
.
foreignIdentifier
=
(
this
.
options
.
as
||
this
.
target
.
tableName
)
+
'Id'
this
.
foreignIdentifier
=
(
this
.
options
.
as
||
this
.
target
.
tableName
)
+
'Id'
}
else
{
}
else
{
this
.
foreignIdentifier
=
this
.
target
.
associations
[
this
.
combinedName
].
identifier
this
.
foreignIdentifier
=
this
.
target
.
associations
[
this
.
associationAccessor
].
identifier
delete
this
.
source
.
attributes
[
this
.
foreignIdentifier
]
delete
this
.
source
.
attributes
[
this
.
foreignIdentifier
]
}
}
...
@@ -47,8 +47,8 @@ HasMany.prototype.injectAttributes = function() {
...
@@ -47,8 +47,8 @@ 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
)
if
(
!
this
.
isSelfAssociation
)
this
.
target
.
associations
[
this
.
combinedName
].
connectorModel
=
this
.
connectorModel
if
(
!
this
.
isSelfAssociation
)
this
.
target
.
associations
[
this
.
associationAccessor
].
connectorModel
=
this
.
connectorModel
this
.
connectorModel
.
sync
()
this
.
connectorModel
.
sync
()
}
else
{
}
else
{
...
...
lib/sequelize/associations/mixin.js
View file @
b98d94f
...
@@ -21,11 +21,10 @@ var Associations = module.exports = {
...
@@ -21,11 +21,10 @@ var Associations = module.exports = {
// the id is in the foreign table or in a connecting table
// the id is in the foreign table or in a connecting table
var
HasMany
=
require
(
"./has-many"
)
var
HasMany
=
require
(
"./has-many"
)
var
association
=
new
HasMany
(
this
,
associatedModel
,
Utils
.
_
.
extend
((
options
||
{}),
this
.
options
))
var
association
=
new
HasMany
(
this
,
associatedModel
,
Utils
.
_
.
extend
((
options
||
{}),
this
.
options
))
this
.
associations
[
association
.
combinedName
]
=
association
.
injectAttributes
()
this
.
associations
[
association
.
associationAccessor
]
=
association
.
injectAttributes
()
}
}
},
},
instanceMethods
:
{
instanceMethods
:
{
}
}
}
}
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