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 5816f037
authored
Dec 27, 2013
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HasOne: Set a default singularized alias if not defined
1 parent
c54f80c3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
lib/associations/has-one.js
test/associations/has-one.test.js
lib/associations/has-one.js
View file @
5816f03
...
...
@@ -14,15 +14,19 @@ module.exports = (function() {
this
.
options
.
foreignKey
=
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
options
.
as
,
this
.
target
.
options
.
language
)
+
"Id"
,
this
.
options
.
underscored
)
}
if
(
!
this
.
options
.
as
)
{
this
.
options
.
as
=
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
)
}
this
.
associationAccessor
=
this
.
isSelfAssociation
?
Utils
.
combineTableNames
(
this
.
target
.
tableName
,
this
.
options
.
as
||
this
.
target
.
tableName
)
?
Utils
.
combineTableNames
(
this
.
target
.
tableName
,
this
.
options
.
as
)
:
this
.
options
.
as
||
this
.
target
.
tableName
this
.
options
.
useHooks
=
options
.
useHooks
this
.
accessors
=
{
get
:
Utils
.
_
.
camelize
(
'get_'
+
(
this
.
options
.
as
||
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
))
),
set
:
Utils
.
_
.
camelize
(
'set_'
+
(
this
.
options
.
as
||
Utils
.
singularize
(
this
.
target
.
tableName
,
this
.
target
.
options
.
language
))
)
get
:
Utils
.
_
.
camelize
(
'get_'
+
this
.
options
.
as
),
set
:
Utils
.
_
.
camelize
(
'set_'
+
this
.
options
.
as
)
}
}
...
...
test/associations/has-one.test.js
View file @
5816f03
...
...
@@ -16,7 +16,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
Group
.
hasOne
(
User
,
{
foreignKey
:
'primaryGroupId'
,
as
:
'primaryUsers'
})
Group
.
hasOne
(
User
,
{
foreignKey
:
'secondaryGroupId'
,
as
:
'secondaryUsers'
})
expect
(
Object
.
keys
(
Group
.
associations
)).
to
.
deep
.
equal
([
'User
s
'
,
'primaryUsers'
,
'secondaryUsers'
])
expect
(
Object
.
keys
(
Group
.
associations
)).
to
.
deep
.
equal
([
'User'
,
'primaryUsers'
,
'secondaryUsers'
])
})
})
...
...
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