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 34f0eacb
authored
Aug 20, 2015
by
Clement Teule
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add additional tests to confirm there are no issues with 1-N association.
1 parent
35683cfe
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
test/integration/instance.test.js
test/integration/instance.test.js
View file @
34f0eac
...
@@ -542,6 +542,106 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
...
@@ -542,6 +542,106 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
});
});
});
});
});
});
it
(
'should set an association to empty after all deletion, 1-N'
,
function
()
{
var
Team
=
this
.
sequelize
.
define
(
'Team'
,
{
name
:
DataTypes
.
STRING
})
,
Player
=
this
.
sequelize
.
define
(
'Player'
,
{
name
:
DataTypes
.
STRING
});
Team
.
hasMany
(
Player
);
Player
.
belongsTo
(
Team
);
return
Team
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Player
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Team
.
create
({
name
:
'the team'
}).
then
(
function
(
team
)
{
return
Player
.
create
({
name
:
'the player1'
}).
then
(
function
(
player1
)
{
return
Player
.
create
({
name
:
'the player2'
}).
then
(
function
(
player2
)
{
return
team
.
setPlayers
([
player1
,
player2
]).
then
(
function
()
{
return
Team
.
findOne
({
where
:
{
id
:
team
.
id
},
include
:
[
Player
]
}).
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
not
.
to
.
be
.
empty
;
return
player1
.
destroy
().
then
(
function
()
{
return
player2
.
destroy
().
then
(
function
()
{
return
leTeam
.
reload
().
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
be
.
empty
;
});
});
});
});
});
});
});
});
});
});
});
it
(
'should update the associations after first element deleted, 1-N'
,
function
()
{
var
Team
=
this
.
sequelize
.
define
(
'Team'
,
{
name
:
DataTypes
.
STRING
})
,
Player
=
this
.
sequelize
.
define
(
'Player'
,
{
name
:
DataTypes
.
STRING
});
Team
.
hasMany
(
Player
);
Player
.
belongsTo
(
Team
);
return
Team
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Player
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Team
.
create
({
name
:
'the team'
}).
then
(
function
(
team
)
{
return
Player
.
create
({
name
:
'the player1'
}).
then
(
function
(
player1
)
{
return
Player
.
create
({
name
:
'the player2'
}).
then
(
function
(
player2
)
{
return
team
.
setPlayers
([
player1
,
player2
]).
then
(
function
()
{
return
Team
.
findOne
({
where
:
{
id
:
team
.
id
},
include
:
[
Player
]
}).
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
have
.
length
(
2
);
return
player2
.
destroy
().
then
(
function
()
{
return
leTeam
.
reload
().
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
have
.
length
(
1
);
expect
(
leTeam
.
Players
[
0
].
name
).
to
.
equal
(
'the player1'
);
});
});
});
});
});
});
});
});
});
});
it
(
'should update the associations after not-first element deleted, 1-N'
,
function
()
{
var
Team
=
this
.
sequelize
.
define
(
'Team'
,
{
name
:
DataTypes
.
STRING
})
,
Player
=
this
.
sequelize
.
define
(
'Player'
,
{
name
:
DataTypes
.
STRING
});
Team
.
hasMany
(
Player
);
Player
.
belongsTo
(
Team
);
return
Team
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Player
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Team
.
create
({
name
:
'the team'
}).
then
(
function
(
team
)
{
return
Player
.
create
({
name
:
'the player1'
}).
then
(
function
(
player1
)
{
return
Player
.
create
({
name
:
'the player2'
}).
then
(
function
(
player2
)
{
return
team
.
setPlayers
([
player1
,
player2
]).
then
(
function
()
{
return
Team
.
findOne
({
where
:
{
id
:
team
.
id
},
include
:
[
Player
]
}).
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
have
.
length
(
2
);
return
player1
.
destroy
().
then
(
function
()
{
return
leTeam
.
reload
().
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
have
.
length
(
1
);
expect
(
leTeam
.
Players
[
0
].
name
).
to
.
equal
(
'the player2'
);
});
});
});
});
});
});
});
});
});
});
});
});
describe
(
'default values'
,
function
()
{
describe
(
'default values'
,
function
()
{
...
...
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