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 93c164bb
authored
Sep 30, 2014
by
Victor Pontis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
single linked has many broken when specifying field
1 parent
7bb9c07e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
1 deletions
test/associations/has-many.test.js
test/associations/has-many.test.js
View file @
93c164b
...
@@ -1476,7 +1476,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1476,7 +1476,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
});
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
});
this
.
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
name
:
DataTypes
.
STRING
});
this
.
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
name
:
DataTypes
.
STRING
});
this
.
Puppy
=
this
.
sequelize
.
define
(
'Puppy'
,
{
breed
:
DataTypes
.
STRING
});
// doubly linked has many
this
.
User
.
hasMany
(
this
.
Project
,
{
this
.
User
.
hasMany
(
this
.
Project
,
{
through
:
'user_projects'
,
through
:
'user_projects'
,
as
:
'Projects'
,
as
:
'Projects'
,
...
@@ -1493,9 +1495,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1493,9 +1495,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
name
:
'projectId'
name
:
'projectId'
}
}
});
});
// singly linked has many
this
.
User
.
hasMany
(
this
.
Puppy
,
{
as
:
'Puppies'
,
foreignKey
:
{
field
:
'user_id'
,
name
:
'userId'
}
});
this
.
Puppy
.
belongsTo
(
this
.
User
,
{
foreignKey
:
{
field
:
'user_id'
,
name
:
'userId'
}
});
});
});
it
(
'should correctly get associations'
,
function
()
{
it
(
'should correctly get associations
when doubly linked
'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Promise
.
all
([
return
Promise
.
all
([
...
@@ -1513,6 +1530,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1513,6 +1530,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
});
});
});
});
it
(
'should correctly get associations when singly linked'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Promise
.
all
([
self
.
User
.
create
({
name
:
'Matt'
}),
self
.
Puppy
.
create
({
breed
:
'Terrier'
})
]);
}).
spread
(
function
(
user
,
puppy
)
{
return
user
.
addPuppy
(
puppy
).
return
(
user
);
}).
then
(
function
(
user
)
{
return
user
.
getPuppies
();
}).
then
(
function
(
puppies
)
{
var
puppy
=
puppies
[
0
];
expect
(
puppy
).
to
.
be
.
defined
;
});
});
it
(
'should be able to handle nested includes properly'
,
function
()
{
it
(
'should be able to handle nested includes properly'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
this
.
Group
=
this
.
sequelize
.
define
(
'Group'
,
{
groupName
:
DataTypes
.
STRING
});
this
.
Group
=
this
.
sequelize
.
define
(
'Group'
,
{
groupName
:
DataTypes
.
STRING
});
...
...
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