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 a093f46c
authored
Jul 16, 2013
by
Daniel Durante
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a spec for hasOne and belongsTo and including those models within another model. Closes #516
1 parent
f3c7939e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
2 deletions
spec/associations/belongs-to.spec.js
spec/associations/mixin.spec.js
spec/associations/belongs-to.spec.js
View file @
a093f46
...
@@ -49,7 +49,6 @@ describe(Helpers.getTestDialectTeaser("BelongsTo"), function() {
...
@@ -49,7 +49,6 @@ describe(Helpers.getTestDialectTeaser("BelongsTo"), function() {
})
})
describe
(
"Foreign key constraints"
,
function
()
{
describe
(
"Foreign key constraints"
,
function
()
{
it
(
"are not enabled by default"
,
function
(
done
)
{
it
(
"are not enabled by default"
,
function
(
done
)
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
...
@@ -176,7 +175,6 @@ describe(Helpers.getTestDialectTeaser("BelongsTo"), function() {
...
@@ -176,7 +175,6 @@ describe(Helpers.getTestDialectTeaser("BelongsTo"), function() {
})
})
})
})
})
})
})
})
describe
(
"Association options"
,
function
()
{
describe
(
"Association options"
,
function
()
{
...
...
spec/associations/mixin.spec.js
View file @
a093f46
...
@@ -28,5 +28,62 @@ describe(Helpers.getTestDialectTeaser("Mixin"), function() {
...
@@ -28,5 +28,62 @@ describe(Helpers.getTestDialectTeaser("Mixin"), function() {
expect
(
User
.
getAssociation
(
Task
).
target
).
toEqual
(
Task
)
expect
(
User
.
getAssociation
(
Task
).
target
).
toEqual
(
Task
)
})
})
it
(
'can handle multiple associations just fine'
,
function
(
done
)
{
var
Emit
=
require
(
'events'
).
EventEmitter
,
emit
=
new
Emit
()
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Event
=
this
.
sequelize
.
define
(
'Event'
,
{
name
:
Sequelize
.
STRING
})
,
Place
=
this
.
sequelize
.
define
(
'Place'
,
{
name
:
Sequelize
.
STRING
})
,
theSQL
=
''
,
count
=
0
,
theEvent
Event
.
belongsTo
(
User
)
Event
.
hasOne
(
Place
)
emit
.
on
(
'sql'
,
function
(
sql
){
++
count
theSQL
=
sql
if
(
count
>
1
)
{
emit
.
emit
(
'spy'
)
}
})
emit
.
on
(
'find'
,
function
(
e
)
{
++
count
theEvent
=
e
if
(
count
>
1
)
{
emit
.
emit
(
'spy'
)
}
})
emit
.
on
(
'spy'
,
function
(){
expect
(
theSQL
.
match
(
/WHERE
[
"`
]
Events
[
"`
]
.
[
"`
]
id
[
"`
]
=1;$/
)).
not
.
toBeNull
()
expect
(
theEvent
.
name
).
toEqual
(
'Bob Marley Concert'
)
expect
(
theEvent
.
place
.
name
).
toEqual
(
'Backyard'
)
expect
(
theEvent
.
user
.
username
).
toEqual
(
'Dan'
)
done
()
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'Dan'
}).
success
(
function
(
user
){
Event
.
create
({
name
:
'Bob Marley Concert'
}).
success
(
function
(
event
)
{
Place
.
create
({
name
:
'Backyard'
}).
success
(
function
(
place
)
{
event
.
setUser
(
user
).
success
(
function
(){
event
.
setPlace
(
place
).
success
(
function
(){
Event
.
find
({
where
:
{
id
:
1
},
include
:
[
User
,
Place
]}).
success
(
function
(
theEvent
){
emit
.
emit
(
'find'
,
theEvent
)
})
.
on
(
'sql'
,
function
(
sql
){
emit
.
emit
(
'sql'
,
sql
)
})
})
})
})
})
})
})
})
})
})
})
})
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