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 ec974a7a
authored
Feb 13, 2016
by
Sushant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(fix-#3295) self reference tests for BelongsToMany
1 parent
46da2409
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
1 deletions
test/integration/associations/belongs-to-many.test.js
test/integration/associations/belongs-to-many.test.js
View file @
ec974a7
...
...
@@ -2059,7 +2059,75 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
});
});
describe
(
'selfAssociations'
,
function
()
{
describe
(
'selfAssociations'
,
function
()
{
it
(
'should work with self reference'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
(
100
)
})
,
Follow
=
this
.
sequelize
.
define
(
'Follow'
)
,
self
=
this
;
User
.
belongsToMany
(
User
,
{
through
:
Follow
,
as
:
'User'
});
User
.
belongsToMany
(
User
,
{
through
:
Follow
,
as
:
'Fan'
});
return
this
.
sequelize
.
sync
({
force
:
true
})
.
then
(
function
()
{
return
self
.
sequelize
.
Promise
.
all
([
User
.
create
({
name
:
'Khsama'
}),
User
.
create
({
name
:
'Vivek'
}),
User
.
create
({
name
:
'Satya'
})
]);
})
.
then
(
function
(
users
)
{
return
self
.
sequelize
.
Promise
.
all
([
users
[
0
].
addFan
(
users
[
1
]),
users
[
1
].
addUser
(
users
[
2
]),
users
[
2
].
addFan
(
users
[
0
])
]);
});
});
it
(
'should work with custom self reference'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
(
100
)
})
,
UserFollowers
=
this
.
sequelize
.
define
(
'UserFollower'
)
,
self
=
this
;
User
.
belongsToMany
(
User
,
{
as
:
{
singular
:
'Follower'
,
plural
:
'Followers'
},
through
:
UserFollowers
});
User
.
belongsToMany
(
User
,
{
as
:
{
singular
:
'Invitee'
,
plural
:
'Invitees'
},
foreignKey
:
'InviteeId'
,
through
:
'Invites'
});
return
this
.
sequelize
.
sync
({
force
:
true
})
.
then
(
function
()
{
return
self
.
sequelize
.
Promise
.
all
([
User
.
create
({
name
:
'Jalrangi'
}),
User
.
create
({
name
:
'Sargrahi'
})
]);
})
.
then
(
function
(
users
)
{
return
self
.
sequelize
.
Promise
.
all
([
users
[
0
].
addFollower
(
users
[
1
]),
users
[
1
].
addFollower
(
users
[
0
]),
users
[
0
].
addInvitee
(
users
[
1
]),
users
[
1
].
addInvitee
(
users
[
0
])
]);
});
});
it
(
'should setup correct foreign keys'
,
function
()
{
/* camcelCase */
var
Person
=
this
.
sequelize
.
define
(
'Person'
)
...
...
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