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 31440b06
authored
Nov 17, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
merge
2 parents
18d8ca6e
6ae09c0c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
4 deletions
lib/associations/belongs-to.js
lib/associations/has-one.js
spec-jasmine/associations/has-many.spec.js
spec-jasmine/associations/has-one.spec.js
lib/associations/belongs-to.js
View file @
31440b0
...
...
@@ -36,9 +36,18 @@ module.exports = (function() {
var
self
=
this
,
accessor
=
Utils
.
_
.
camelize
(
'get_'
+
(
this
.
options
.
as
||
Utils
.
singularize
(
this
.
target
.
tableName
)))
obj
[
accessor
]
=
function
()
{
obj
[
accessor
]
=
function
(
params
)
{
var
id
=
this
[
self
.
identifier
]
return
self
.
target
.
find
(
id
)
if
(
!
Utils
.
_
.
isUndefined
(
params
))
{
if
(
!
Utils
.
_
.
isUndefined
(
params
.
attributes
))
{
params
=
Utils
.
_
.
extend
({
where
:
{
id
:
id
}},
params
)
}
}
else
{
params
=
id
}
return
self
.
target
.
find
(
params
)
}
return
this
...
...
lib/associations/has-one.js
View file @
31440b0
...
...
@@ -40,12 +40,21 @@ module.exports = (function() {
HasOne
.
prototype
.
injectGetter
=
function
(
obj
)
{
var
self
=
this
obj
[
this
.
accessors
.
get
]
=
function
()
{
obj
[
this
.
accessors
.
get
]
=
function
(
params
)
{
var
id
=
this
.
id
,
where
=
{}
where
[
self
.
identifier
]
=
id
return
self
.
target
.
find
({
where
:
where
})
if
(
!
Utils
.
_
.
isUndefined
(
params
))
{
if
(
!
Utils
.
_
.
isUndefined
(
params
.
attributes
))
{
params
=
Utils
.
_
.
extend
({
where
:
where
},
params
)
}
}
else
{
params
=
{
where
:
where
}
}
return
self
.
target
.
find
(
params
)
}
return
this
...
...
spec-jasmine/associations/has-many.spec.js
View file @
31440b0
...
...
@@ -87,11 +87,15 @@ describe('HasMany', function() {
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
user
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
user
.
getTasks
({
attributes
:
[
'title'
]}).
success
(
function
(
tasks
)
{
expect
(
tasks
[
0
].
selectedValues
.
title
).
toEqual
(
'task1'
)
expect
(
tasks
[
0
].
selectedValues
.
id
).
toEqual
(
null
)
done
()
})
})
})
})
})
it
(
"should allow selfAssociation to be single linked (only one DAO is created)"
,
function
()
{
var
oldLength
=
sequelize
.
daoFactoryManager
.
daos
.
length
;
...
...
spec-jasmine/associations/has-one.spec.js
View file @
31440b0
...
...
@@ -88,11 +88,15 @@ describe('HasOne', function() {
user
.
setTask
(
task
).
on
(
'success'
,
function
()
{
user
.
getTask
().
on
(
'success'
,
function
(
task2
)
{
expect
(
task
.
title
).
toEqual
(
task2
.
title
)
user
.
getTask
({
attributes
:
[
'title'
]}).
on
(
'success'
,
function
(
task2
)
{
expect
(
task2
.
selectedValues
.
title
).
toEqual
(
'snafu'
)
expect
(
task2
.
selectedValues
.
id
).
toEqual
(
null
)
done
()
})
})
})
})
})
it
(
"unsets unassociated objects"
,
function
()
{
var
user
,
task1
,
task2
;
...
...
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