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 da715a16
authored
Aug 23, 2015
by
Sorin Neacsu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Queries with includes with separate:true now add the source id to the attributes if it was missing
1 parent
673a59bd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
lib/model.js
test/integration/include/seperate.test.js
lib/model.js
View file @
da715a1
...
@@ -610,6 +610,10 @@ validateIncludedElement = function(include, tableNames, options) {
...
@@ -610,6 +610,10 @@ validateIncludedElement = function(include, tableNames, options) {
include
.
duplicating
=
false
;
include
.
duplicating
=
false
;
}
}
if
(
include
.
separate
===
true
&&
options
.
attributes
&&
options
.
attributes
.
length
&&
!
_
.
includes
(
options
.
attributes
,
association
.
source
.
primaryKeyAttribute
))
{
options
.
attributes
.
push
(
association
.
source
.
primaryKeyAttribute
);
}
// Validate child includes
// Validate child includes
if
(
include
.
hasOwnProperty
(
'include'
))
{
if
(
include
.
hasOwnProperty
(
'include'
))
{
validateIncludedElements
.
call
(
include
.
model
,
include
,
tableNames
,
options
);
validateIncludedElements
.
call
(
include
.
model
,
include
,
tableNames
,
options
);
...
...
test/integration/include/seperate.test.js
View file @
da715a1
...
@@ -6,6 +6,7 @@ var chai = require('chai')
...
@@ -6,6 +6,7 @@ var chai = require('chai')
,
sinon
=
require
(
'sinon'
)
,
sinon
=
require
(
'sinon'
)
,
Support
=
require
(
__dirname
+
'/../support'
)
,
Support
=
require
(
__dirname
+
'/../support'
)
,
Sequelize
=
require
(
__dirname
+
'/../../../index'
)
,
Sequelize
=
require
(
__dirname
+
'/../../../index'
)
,
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
)
,
current
=
Support
.
sequelize
,
current
=
Support
.
sequelize
,
Promise
=
Sequelize
.
Promise
,
Promise
=
Sequelize
.
Promise
,
_
=
require
(
'lodash'
);
,
_
=
require
(
'lodash'
);
...
@@ -60,6 +61,44 @@ if (current.dialect.supports.groupedLimit) {
...
@@ -60,6 +61,44 @@ if (current.dialect.supports.groupedLimit) {
});
});
});
});
it
(
'should work even if the id was not included'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{})
,
sqlSpy
=
sinon
.
spy
();
User
.
Tasks
=
User
.
hasMany
(
Task
,
{
as
:
'tasks'
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
({
id
:
1
,
tasks
:
[
{},
{},
{}
]
},
{
include
:
[
User
.
Tasks
]
}).
then
(
function
()
{
return
User
.
findAll
({
attributes
:
[
'name'
],
include
:
[
{
association
:
User
.
Tasks
,
separate
:
true
}
],
order
:
[
[
'id'
,
'ASC'
]
],
logging
:
sqlSpy
});
}).
then
(
function
(
users
)
{
expect
(
users
[
0
].
get
(
'tasks'
)).
to
.
be
.
ok
;
expect
(
users
[
0
].
get
(
'tasks'
).
length
).
to
.
equal
(
3
);
expect
(
sqlSpy
).
to
.
have
.
been
.
calledTwice
;
});
});
});
it
(
'should not break a nested include with null values'
,
function
()
{
it
(
'should not break a nested include with null values'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
Team
=
this
.
sequelize
.
define
(
'Team'
,
{})
,
Team
=
this
.
sequelize
.
define
(
'Team'
,
{})
...
...
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