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 f5f3adf6
authored
Feb 26, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check if the association uses the right alias
1 parent
bf8246bc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
4 deletions
lib/dao-factory.js
spec/dao-factory.spec.js
lib/dao-factory.js
View file @
f5f3adf
...
...
@@ -391,7 +391,7 @@ module.exports = (function() {
,
association
=
(
usesAlias
?
this
.
getAssociationByAlias
(
include
.
as
)
:
this
.
getAssociation
(
include
.
daoFactory
))
// check if the current daoFactory is actually associated with the passed daoFactory
if
(
!!
association
)
{
if
(
!!
association
&&
(
!
association
.
options
.
as
||
(
association
.
options
.
as
===
include
.
as
))
)
{
include
.
association
=
association
return
include
...
...
spec/dao-factory.spec.js
View file @
f5f3adf
...
...
@@ -472,7 +472,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
this
.
Worker
=
this
.
sequelize
.
define
(
'Worker'
,
{
name
:
Sequelize
.
STRING
})
})
describe
(
'=>belongsTo
only
'
,
function
()
{
describe
(
'=>belongsTo'
,
function
()
{
before
(
function
(
done
)
{
this
.
Task
.
belongsTo
(
this
.
Worker
)
...
...
@@ -520,7 +520,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
})
})
describe
(
'=>hasOne
only
'
,
function
()
{
describe
(
'=>hasOne'
,
function
()
{
before
(
function
(
done
)
{
this
.
Worker
.
hasOne
(
this
.
Task
)
...
...
@@ -556,7 +556,49 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
})
})
describe
(
'=>hasMany only'
,
function
()
{
describe
(
'=>hasOne with alias'
,
function
()
{
before
(
function
(
done
)
{
this
.
Worker
.
hasOne
(
this
.
Task
,
{
as
:
'ToDo'
})
this
.
sequelize
.
sync
({
force
:
true
}).
complete
(
function
()
{
this
.
Worker
.
create
({
name
:
'worker'
}).
success
(
function
(
worker
)
{
this
.
Task
.
create
({
title
:
'homework'
}).
success
(
function
(
task
)
{
this
.
worker
=
worker
this
.
task
=
task
this
.
worker
.
setToDo
(
this
.
task
).
success
(
done
)
}.
bind
(
this
))
}.
bind
(
this
))
}.
bind
(
this
))
})
it
(
'throws an error if included DaoFactory is not referenced by alias'
,
function
()
{
Helpers
.
assertException
(
function
()
{
this
.
Worker
.
find
({
include
:
[
this
.
Task
]
})
}.
bind
(
this
),
'Task is not associated to Worker!'
)
})
it
(
'throws an error if alias is not associated'
,
function
()
{
Helpers
.
assertException
(
function
()
{
this
.
Worker
.
find
({
include
:
[
{
daoFactory
:
this
.
Task
,
as
:
'Work'
}
]
})
}.
bind
(
this
),
'Task (Work) is not associated to Worker!'
)
})
it
(
'returns the associated task via worker.task'
,
function
(
done
)
{
this
.
Worker
.
find
({
where
:
{
id
:
this
.
worker
.
id
},
include
:
[
{
daoFactory
:
this
.
Task
,
as
:
'ToDo'
}
]
}).
complete
(
function
(
err
,
worker
)
{
expect
(
err
).
toBeNull
()
expect
(
worker
).
toBeDefined
()
expect
(
worker
.
toDo
).
toBeDefined
()
expect
(
worker
.
toDo
.
title
).
toEqual
(
'homework'
)
done
()
}.
bind
(
this
))
})
})
describe
(
'=>hasMany'
,
function
()
{
before
(
function
(
done
)
{
this
.
Worker
.
hasMany
(
this
.
Task
)
...
...
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