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 78848c5b
authored
May 09, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed self associated has-one associations
1 parent
b98d94f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
2 deletions
lib/sequelize/associations/has-one.js
lib/sequelize/associations/mixin.js
lib/sequelize/associations/has-one.js
View file @
78848c5
...
@@ -5,6 +5,12 @@ var HasOne = module.exports = function(srcModel, targetModel, options) {
...
@@ -5,6 +5,12 @@ var HasOne = module.exports = function(srcModel, targetModel, options) {
this
.
source
=
srcModel
this
.
source
=
srcModel
this
.
target
=
targetModel
this
.
target
=
targetModel
this
.
options
=
options
this
.
options
=
options
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableName
)
this
.
associationAccessor
=
this
.
isSelfAssociation
?
Utils
.
combineTableNames
(
this
.
target
.
tableName
,
this
.
options
.
as
||
this
.
target
.
tableName
)
:
this
.
target
.
tableName
this
.
accessors
=
{
this
.
accessors
=
{
get
:
Utils
.
_
.
camelize
(
'get_'
+
(
this
.
options
.
as
||
Utils
.
singularize
(
this
.
target
.
tableName
))),
get
:
Utils
.
_
.
camelize
(
'get_'
+
(
this
.
options
.
as
||
Utils
.
singularize
(
this
.
target
.
tableName
))),
set
:
Utils
.
_
.
camelize
(
'set_'
+
(
this
.
options
.
as
||
Utils
.
singularize
(
this
.
target
.
tableName
)))
set
:
Utils
.
_
.
camelize
(
'set_'
+
(
this
.
options
.
as
||
Utils
.
singularize
(
this
.
target
.
tableName
)))
...
@@ -49,7 +55,7 @@ HasOne.prototype.injectSetter = function(obj) {
...
@@ -49,7 +55,7 @@ HasOne.prototype.injectSetter = function(obj) {
associatedObject
[
self
.
identifier
]
=
obj
.
id
associatedObject
[
self
.
identifier
]
=
obj
.
id
associatedObject
.
save
()
associatedObject
.
save
()
.
on
(
'success'
,
function
()
{
customEventEmitter
.
emit
(
'success'
,
''
)
})
.
on
(
'success'
,
function
()
{
customEventEmitter
.
emit
(
'success'
,
associatedObject
)
})
.
on
(
'failure'
,
function
(
err
)
{
customEventEmitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'failure'
,
function
(
err
)
{
customEventEmitter
.
emit
(
'failure'
,
err
)
})
})
})
})
})
...
...
lib/sequelize/associations/mixin.js
View file @
78848c5
...
@@ -9,7 +9,7 @@ var Associations = module.exports = {
...
@@ -9,7 +9,7 @@ var Associations = module.exports = {
// the id is in the foreign table
// the id is in the foreign table
var
HasOne
=
require
(
'./has-one'
)
var
HasOne
=
require
(
'./has-one'
)
var
association
=
new
HasOne
(
this
,
associatedModel
,
Utils
.
_
.
extend
((
options
||
{}),
this
.
options
))
var
association
=
new
HasOne
(
this
,
associatedModel
,
Utils
.
_
.
extend
((
options
||
{}),
this
.
options
))
this
.
associations
[
associat
edModel
.
tableName
]
=
association
.
injectAttributes
()
this
.
associations
[
associat
ion
.
associationAccessor
]
=
association
.
injectAttributes
()
},
},
belongsTo
:
function
(
associatedModel
,
options
)
{
belongsTo
:
function
(
associatedModel
,
options
)
{
// the id is in this table
// the id is in this table
...
...
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