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 844657a0
authored
Jan 30, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes fixes fixes
1 parent
4a184db6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
13 deletions
lib/dao-factory.js
lib/dialects/abstract/query-generator.js
test/dao-factory/find.test.js
test/include/findAll.test.js
lib/dao-factory.js
View file @
844657a
...
...
@@ -1335,8 +1335,8 @@ module.exports = (function() {
options
.
includeMap
[
include
.
as
]
=
include
options
.
includeNames
.
push
(
include
.
as
)
if
(
include
.
association
.
isMultiAssociation
)
options
.
hasMultiAssociation
=
true
if
(
include
.
association
.
isSingleAssociation
)
options
.
hasSingleAssociation
=
true
if
(
include
.
association
.
isMultiAssociation
||
include
.
hasMultiAssociation
)
options
.
hasMultiAssociation
=
true
if
(
include
.
association
.
isSingleAssociation
||
include
.
hasSingleAssociation
)
options
.
hasSingleAssociation
=
true
options
.
hasIncludeWhere
=
options
.
hasIncludeWhere
||
include
.
hasIncludeWhere
||
!!
include
.
where
options
.
hasIncludeRequired
=
options
.
hasIncludeRequired
||
include
.
hasIncludeRequired
||
!!
include
.
required
...
...
lib/dialects/abstract/query-generator.js
View file @
844657a
...
...
@@ -473,8 +473,8 @@ module.exports = (function() {
,
mainQueryItems
=
[]
,
mainAttributes
=
options
.
attributes
,
mainJoinQueries
=
[]
// We'll use a subquery if we have hasMany associations and a limit
or
a filtered/required association
,
subQuery
=
(
limit
||
options
.
hasIncludeWhere
||
options
.
hasIncludeRequired
)
&&
options
.
hasMultiAssociation
// We'll use a subquery if we have hasMany associations and a limit
and
a filtered/required association
,
subQuery
=
limit
&&
(
options
.
hasIncludeWhere
||
options
.
hasIncludeRequired
||
options
.
hasMultiAssociation
)
,
subQueryItems
=
[]
,
subQueryAttributes
=
null
,
subJoinQueries
=
[]
...
...
@@ -484,6 +484,10 @@ module.exports = (function() {
return
this
.
quoteIdentifiers
(
t
)
}.
bind
(
this
)).
join
(
", "
)
if
(
subQuery
&&
mainAttributes
)
{
mainAttributes
=
mainAttributes
.
concat
(
factory
.
hasPrimaryKeys
?
factory
.
primaryKeyAttributes
:
[
'id'
])
}
// Escape attributes
mainAttributes
=
mainAttributes
&&
mainAttributes
.
map
(
function
(
attr
){
var
addTable
=
true
...
...
@@ -518,6 +522,7 @@ module.exports = (function() {
// If subquery, we ad the mainAttributes to the subQuery and set the mainAttributes to select * from subquery
if
(
subQuery
)
{
// We need primary keys
subQueryAttributes
=
mainAttributes
mainAttributes
=
[
options
.
table
+
'.*'
]
}
...
...
test/dao-factory/find.test.js
View file @
844657a
...
...
@@ -237,8 +237,9 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
self
.
User
.
find
({
where
:
{
username
:
'JohnXOXOXO'
},
attributes
:
[
'username'
]
}).
success
(
function
(
user
)
{
expect
(
user
.
selectedValues
).
to
.
have
.
property
(
'username'
,
'JohnXOXOXO'
)
}).
done
(
function
(
err
,
user
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
_
.
omit
(
user
.
selectedValues
,
[
'id'
])).
to
.
have
.
property
(
'username'
,
'JohnXOXOXO'
)
done
()
})
})
...
...
@@ -262,8 +263,9 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
where
:
{
username
:
'John DOE'
},
attributes
:
[
'username'
],
include
:
[
self
.
Mission
]
}).
success
(
function
(
user
)
{
expect
(
user
.
selectedValues
).
to
.
deep
.
equal
({
username
:
'John DOE'
})
}).
done
(
function
(
err
,
user
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
_
.
omit
(
user
.
selectedValues
,
[
'id'
])).
to
.
deep
.
equal
({
username
:
'John DOE'
})
done
()
})
})
...
...
@@ -291,7 +293,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
attributes
:
[
'username'
],
include
:
[{
model
:
self
.
Mission
,
as
:
self
.
Mission
.
tableName
,
attributes
:
[
'title'
]}]
}).
success
(
function
(
user
)
{
expect
(
user
.
selectedValues
).
to
.
deep
.
equal
({
username
:
'Brain Picker'
})
expect
(
_
.
omit
(
user
.
selectedValues
,
[
'id'
])
).
to
.
deep
.
equal
({
username
:
'Brain Picker'
})
expect
(
user
.
missions
[
0
].
selectedValues
).
to
.
deep
.
equal
({
id
:
1
,
title
:
'another mission!!'
})
expect
(
user
.
missions
[
0
].
foo
).
not
.
to
.
exist
done
()
...
...
test/include/findAll.test.js
View file @
844657a
...
...
@@ -895,7 +895,9 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
it
(
'should be possible to extend the on clause with a where option on nested includes'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
})
,
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
title
:
DataTypes
.
STRING
})
...
...
@@ -984,7 +986,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
async
.
auto
({
user
:
function
(
callback
)
{
User
.
create
().
done
(
callback
)
User
.
create
(
{
name
:
'FooBarzz'
}
).
done
(
callback
)
},
memberships
:
[
'user'
,
function
(
callback
,
results
)
{
GroupMember
.
bulkCreate
([
...
...
@@ -1123,22 +1125,26 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
it
(
'should be possible use limit and a where on a belongsTo with additional hasMany includes'
,
function
(
done
)
{
it
(
'should be possible use limit
, attributes
and a where on a belongsTo with additional hasMany includes'
,
function
(
done
)
{
var
self
=
this
this
.
fixtureA
(
function
()
{
self
.
models
.
Product
.
findAll
({
attributes
:
[
'title'
],
include
:
[
{
model
:
self
.
models
.
Company
,
where
:
{
name
:
'NYSE'
}},
{
model
:
self
.
models
.
Tag
},
{
model
:
self
.
models
.
Price
}
],
limit
:
3
,
order
:
'id ASC'
order
:
[
[
self
.
sequelize
.
col
(
self
.
models
.
Product
.
tableName
+
'.id'
),
'ASC'
]
]
}).
done
(
function
(
err
,
products
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
products
.
length
).
to
.
equal
(
3
)
products
.
forEach
(
function
(
product
)
{
expect
(
product
.
company
.
name
).
to
.
equal
(
'NYSE'
)
expect
(
product
.
tags
.
length
).
to
.
be
.
ok
expect
(
product
.
prices
.
length
).
to
.
be
.
ok
})
...
...
@@ -1151,6 +1157,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
var
self
=
this
this
.
fixtureA
(
function
()
{
self
.
models
.
Product
.
findAll
({
include
:
[
{
model
:
self
.
models
.
Company
},
{
model
:
self
.
models
.
Tag
},
...
...
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