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 17228481
authored
Feb 07, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use getWhereConditions for include.where
1 parent
7e9c69af
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
22 deletions
lib/dialects/abstract/query-generator.js
lib/utils.js
test/include.test.js
test/include/findAll.test.js
lib/dialects/abstract/query-generator.js
View file @
1722848
...
@@ -604,19 +604,12 @@ module.exports = (function() {
...
@@ -604,19 +604,12 @@ module.exports = (function() {
,
includeWhere
=
{}
,
includeWhere
=
{}
,
whereOptions
=
Utils
.
_
.
clone
(
options
)
,
whereOptions
=
Utils
.
_
.
clone
(
options
)
whereOptions
.
keysEscaped
=
true
if
(
tableName
!==
parentTable
)
{
if
(
tableName
!==
parentTable
)
{
as
=
parentTable
+
'.'
+
include
.
as
as
=
parentTable
+
'.'
+
include
.
as
}
}
if
(
include
.
where
)
{
for
(
var
key
in
include
.
where
)
{
if
(
include
.
where
.
hasOwnProperty
(
key
))
{
includeWhere
[
self
.
quoteIdentifier
(
as
)
+
'.'
+
self
.
quoteIdentifiers
(
key
)]
=
include
.
where
[
key
]
}
}
whereOptions
.
keysEscaped
=
true
}
// includeIgnoreAttributes is used by aggregate functions
// includeIgnoreAttributes is used by aggregate functions
if
(
options
.
includeIgnoreAttributes
!==
false
)
{
if
(
options
.
includeIgnoreAttributes
!==
false
)
{
attributes
=
include
.
attributes
.
map
(
function
(
attr
)
{
attributes
=
include
.
attributes
.
map
(
function
(
attr
)
{
...
@@ -677,7 +670,7 @@ module.exports = (function() {
...
@@ -677,7 +670,7 @@ module.exports = (function() {
if
(
include
.
where
)
{
if
(
include
.
where
)
{
targetWhere
=
self
.
hashToWhereConditions
(
includeWhere
,
include
.
daoFactory
,
whereOptions
)
targetWhere
=
self
.
getWhereConditions
(
include
.
where
,
self
.
sequelize
.
literal
(
self
.
quoteIdentifier
(
as
))
,
include
.
daoFactory
,
whereOptions
)
joinQueryItem
+=
" AND "
+
targetWhere
joinQueryItem
+=
" AND "
+
targetWhere
if
(
subQuery
)
{
if
(
subQuery
)
{
if
(
!
options
.
where
)
options
.
where
=
{}
if
(
!
options
.
where
)
options
.
where
=
{}
...
@@ -711,7 +704,7 @@ module.exports = (function() {
...
@@ -711,7 +704,7 @@ module.exports = (function() {
joinQueryItem
+=
where
joinQueryItem
+=
where
if
(
include
.
where
)
{
if
(
include
.
where
)
{
joinQueryItem
+=
" AND "
+
self
.
hashToWhereConditions
(
includeWhere
,
include
.
daoFactory
,
whereOptions
)
joinQueryItem
+=
" AND "
+
self
.
getWhereConditions
(
include
.
where
,
self
.
sequelize
.
literal
(
self
.
quoteIdentifier
(
as
))
,
include
.
daoFactory
,
whereOptions
)
// If its a multi association we need to add a where query to the main where (executed in the subquery)
// If its a multi association we need to add a where query to the main where (executed in the subquery)
if
(
subQuery
&&
association
.
isMultiAssociation
)
{
if
(
subQuery
&&
association
.
isMultiAssociation
)
{
...
@@ -890,8 +883,9 @@ module.exports = (function() {
...
@@ -890,8 +883,9 @@ module.exports = (function() {
,
where
=
{}
,
where
=
{}
,
self
=
this
,
self
=
this
if
(
typeof
prepend
===
'undefined'
)
if
(
typeof
prepend
===
'undefined'
)
{
prepend
=
true
prepend
=
true
}
if
((
smth
instanceof
Utils
.
and
)
||
(
smth
instanceof
Utils
.
or
))
{
if
((
smth
instanceof
Utils
.
and
)
||
(
smth
instanceof
Utils
.
or
))
{
var
connector
=
(
smth
instanceof
Utils
.
and
)
?
' AND '
:
' OR '
var
connector
=
(
smth
instanceof
Utils
.
and
)
?
' AND '
:
' OR '
...
@@ -903,8 +897,8 @@ module.exports = (function() {
...
@@ -903,8 +897,8 @@ module.exports = (function() {
result
=
"("
+
result
+
")"
result
=
"("
+
result
+
")"
}
else
if
(
Utils
.
isHash
(
smth
))
{
}
else
if
(
Utils
.
isHash
(
smth
))
{
if
(
prepend
)
{
if
(
prepend
)
{
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
smth
)
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
smth
,
self
.
quoteIdentifier
.
bind
(
self
)
)
}
}
result
=
this
.
hashToWhereConditions
(
smth
,
factory
,
options
)
result
=
this
.
hashToWhereConditions
(
smth
,
factory
,
options
)
}
else
if
(
typeof
smth
===
'number'
)
{
}
else
if
(
typeof
smth
===
'number'
)
{
var
primaryKeys
=
!!
factory
?
Object
.
keys
(
factory
.
primaryKeys
)
:
[]
var
primaryKeys
=
!!
factory
?
Object
.
keys
(
factory
.
primaryKeys
)
:
[]
...
...
lib/utils.js
View file @
1722848
...
@@ -445,7 +445,7 @@ var Utils = module.exports = {
...
@@ -445,7 +445,7 @@ var Utils = module.exports = {
return
result
return
result
},
},
prependTableNameToHash
:
function
(
tableName
,
hash
)
{
prependTableNameToHash
:
function
(
tableName
,
hash
,
quote
)
{
if
(
tableName
)
{
if
(
tableName
)
{
var
_hash
=
{}
var
_hash
=
{}
...
@@ -453,7 +453,11 @@ var Utils = module.exports = {
...
@@ -453,7 +453,11 @@ var Utils = module.exports = {
if
(
key
instanceof
Utils
.
literal
)
{
if
(
key
instanceof
Utils
.
literal
)
{
_hash
[
key
]
=
hash
[
key
]
_hash
[
key
]
=
hash
[
key
]
}
else
if
(
key
.
indexOf
(
'.'
)
===
-
1
)
{
}
else
if
(
key
.
indexOf
(
'.'
)
===
-
1
)
{
_hash
[
tableName
+
'.'
+
key
]
=
hash
[
key
]
if
(
tableName
instanceof
Utils
.
literal
)
{
_hash
[
tableName
+
'.'
+
quote
(
key
)]
=
hash
[
key
]
}
else
{
_hash
[
tableName
+
'.'
+
key
]
=
hash
[
key
]
}
}
else
{
}
else
{
_hash
[
key
]
=
hash
[
key
]
_hash
[
key
]
=
hash
[
key
]
}
}
...
...
test/include.test.js
View file @
1722848
...
@@ -514,7 +514,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
...
@@ -514,7 +514,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
})
})
describe
.
only
(
'where'
,
function
()
{
describe
(
'where'
,
function
()
{
it
(
'should support Sequelize.and()'
,
function
(
done
)
{
it
(
'should support Sequelize.and()'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
Item
=
this
.
sequelize
.
define
(
'Item'
,
{
'test'
:
DataTypes
.
STRING
})
,
Item
=
this
.
sequelize
.
define
(
'Item'
,
{
'test'
:
DataTypes
.
STRING
})
...
@@ -612,8 +612,6 @@ describe(Support.getTestDialectTeaser("Include"), function () {
...
@@ -612,8 +612,6 @@ describe(Support.getTestDialectTeaser("Include"), function () {
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
result
.
length
).
to
.
eql
(
2
)
expect
(
result
.
length
).
to
.
eql
(
2
)
done
()
done
()
}).
on
(
'sql'
,
function
(
sql
)
{
console
.
log
(
sql
)
})
})
})
})
})
})
...
...
test/include/findAll.test.js
View file @
1722848
...
@@ -1073,7 +1073,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
...
@@ -1073,7 +1073,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
})
})
it
(
'should be possible use limit and a where with a belongsTo include'
,
function
(
done
)
{
it
(
'should be possible
to
use limit and a where with a belongsTo include'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
Group
=
this
.
sequelize
.
define
(
'Group'
,
{
,
Group
=
this
.
sequelize
.
define
(
'Group'
,
{
name
:
DataTypes
.
STRING
name
:
DataTypes
.
STRING
...
@@ -1153,7 +1153,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
...
@@ -1153,7 +1153,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
})
})
it
(
'should be possible use limit and a where on a hasMany with additional includes'
,
function
(
done
)
{
it
(
'should be possible
to
use limit and a where on a hasMany with additional includes'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
this
.
fixtureA
(
function
()
{
this
.
fixtureA
(
function
()
{
self
.
models
.
Product
.
findAll
({
self
.
models
.
Product
.
findAll
({
...
@@ -1184,7 +1184,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
...
@@ -1184,7 +1184,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
})
})
it
(
'should be possible use limit and a where on a hasMany with a through model with additional includes'
,
function
(
done
)
{
it
(
'should be possible
to
use limit and a where on a hasMany with a through model with additional includes'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
this
.
fixtureA
(
function
()
{
this
.
fixtureA
(
function
()
{
self
.
models
.
Product
.
findAll
({
self
.
models
.
Product
.
findAll
({
...
...
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