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 c54f80c3
authored
Dec 27, 2013
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
normalize belongs-to to match other associations
1 parent
f66efc26
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
lib/associations/belongs-to.js
lib/associations/belongs-to.js
View file @
c54f80c
...
@@ -14,8 +14,6 @@ module.exports = (function() {
...
@@ -14,8 +14,6 @@ module.exports = (function() {
this
.
options
.
foreignKey
=
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
options
.
as
,
this
.
source
.
options
.
language
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
this
.
options
.
foreignKey
=
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
options
.
as
,
this
.
source
.
options
.
language
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
}
}
this
.
options
.
useHooks
=
options
.
useHooks
if
(
!
this
.
options
.
as
)
{
if
(
!
this
.
options
.
as
)
{
this
.
options
.
as
=
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
)
this
.
options
.
as
=
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
)
}
}
...
@@ -23,6 +21,13 @@ module.exports = (function() {
...
@@ -23,6 +21,13 @@ module.exports = (function() {
this
.
associationAccessor
=
this
.
isSelfAssociation
this
.
associationAccessor
=
this
.
isSelfAssociation
?
Utils
.
combineTableNames
(
this
.
target
.
tableName
,
this
.
options
.
as
)
?
Utils
.
combineTableNames
(
this
.
target
.
tableName
,
this
.
options
.
as
)
:
this
.
options
.
as
:
this
.
options
.
as
this
.
options
.
useHooks
=
options
.
useHooks
this
.
accessors
=
{
get
:
Utils
.
_
.
camelize
(
'get_'
+
this
.
options
.
as
),
set
:
Utils
.
_
.
camelize
(
'set_'
+
this
.
options
.
as
)
}
}
}
// the id is in the source table
// the id is in the source table
...
@@ -44,11 +49,10 @@ module.exports = (function() {
...
@@ -44,11 +49,10 @@ module.exports = (function() {
BelongsTo
.
prototype
.
injectGetter
=
function
(
obj
)
{
BelongsTo
.
prototype
.
injectGetter
=
function
(
obj
)
{
var
self
=
this
var
self
=
this
,
accessor
=
Utils
.
_
.
camelize
(
'get_'
+
this
.
options
.
as
)
,
primaryKeys
=
Object
.
keys
(
self
.
target
.
primaryKeys
)
,
primaryKeys
=
Object
.
keys
(
self
.
target
.
primaryKeys
)
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
obj
[
accessor
]
=
function
(
params
)
{
obj
[
this
.
accessors
.
get
]
=
function
(
params
)
{
var
id
=
this
[
self
.
identifier
]
var
id
=
this
[
self
.
identifier
]
,
where
=
{}
,
where
=
{}
,
options
=
Utils
.
_
.
pick
(
params
||
{},
'transaction'
)
,
options
=
Utils
.
_
.
pick
(
params
||
{},
'transaction'
)
...
@@ -73,9 +77,8 @@ module.exports = (function() {
...
@@ -73,9 +77,8 @@ module.exports = (function() {
BelongsTo
.
prototype
.
injectSetter
=
function
(
obj
)
{
BelongsTo
.
prototype
.
injectSetter
=
function
(
obj
)
{
var
self
=
this
var
self
=
this
,
accessor
=
Utils
.
_
.
camelize
(
'set_'
+
this
.
options
.
as
)
obj
[
accessor
]
=
function
(
associatedObject
,
options
)
{
obj
[
this
.
accessors
.
set
]
=
function
(
associatedObject
,
options
)
{
var
primaryKeys
=
!!
associatedObject
&&
!!
associatedObject
.
daoFactory
?
Object
.
keys
(
associatedObject
.
daoFactory
.
primaryKeys
)
:
[]
var
primaryKeys
=
!!
associatedObject
&&
!!
associatedObject
.
daoFactory
?
Object
.
keys
(
associatedObject
.
daoFactory
.
primaryKeys
)
:
[]
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
...
...
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