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 0b354f5b
authored
Feb 02, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into milestones/2.0.0
2 parents
a54e1c78
de3a7360
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
28 deletions
changelog.md
lib/dao-factory.js
lib/dialects/abstract/query.js
lib/query-interface.js
changelog.md
View file @
0b354f5
...
@@ -6,6 +6,8 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
...
@@ -6,6 +6,8 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
-
fixes issues with migrations/queryInterface createTable and enums
-
fixes issues with migrations/queryInterface createTable and enums
-
migration/queryInterface.addIndex() no longer fals on reserved keywords like 'from'
-
migration/queryInterface.addIndex() no longer fals on reserved keywords like 'from'
-
bulkCreate now supports a
`ignoreDuplicates`
option for MySQL, SQLite and MariaDB that will use
`INSERT IGNORE`
-
bulkCreate now supports a
`ignoreDuplicates`
option for MySQL, SQLite and MariaDB that will use
`INSERT IGNORE`
-
fixes regression bug with 1:M self associations
-
significant performance improvements for 1:1 and single primary key includes for 500+ rows
[
#1333
](
https://github.com/sequelize/sequelize/pull/1333
)
#### Backwards compatability changes
#### Backwards compatability changes
-
find/findAll will now always return primary keys regardless of
`attributes`
settings. (Motivation was to fix various issues with eager loading)
-
find/findAll will now always return primary keys regardless of
`attributes`
settings. (Motivation was to fix various issues with eager loading)
...
...
lib/dao-factory.js
View file @
0b354f5
...
@@ -655,16 +655,7 @@ module.exports = (function() {
...
@@ -655,16 +655,7 @@ module.exports = (function() {
validateIncludedElements
.
call
(
this
,
options
)
validateIncludedElements
.
call
(
this
,
options
)
}
}
if
(
options
.
includeNames
)
{
return
new
this
.
DAO
(
values
,
options
)
options
.
includeNames
=
options
.
includeNames
.
concat
(
options
.
includeNames
.
map
(
function
(
key
)
{
return
key
.
slice
(
0
,
1
).
toLowerCase
()
+
key
.
slice
(
1
)
}))
}
var
self
=
this
,
instance
=
new
this
.
DAO
(
values
,
options
)
return
instance
}
}
DAOFactory
.
prototype
.
create
=
function
(
values
,
fieldsOrOptions
)
{
DAOFactory
.
prototype
.
create
=
function
(
values
,
fieldsOrOptions
)
{
...
@@ -1347,6 +1338,7 @@ module.exports = (function() {
...
@@ -1347,6 +1338,7 @@ module.exports = (function() {
options
.
includeMap
[
include
.
as
]
=
include
options
.
includeMap
[
include
.
as
]
=
include
options
.
includeNames
.
push
(
include
.
as
)
options
.
includeNames
.
push
(
include
.
as
)
options
.
includeNames
.
push
(
include
.
as
.
substr
(
0
,
1
).
toLowerCase
()
+
include
.
as
.
substr
(
1
))
if
(
include
.
association
.
isMultiAssociation
||
include
.
hasMultiAssociation
)
options
.
hasMultiAssociation
=
true
if
(
include
.
association
.
isMultiAssociation
||
include
.
hasMultiAssociation
)
options
.
hasMultiAssociation
=
true
if
(
include
.
association
.
isSingleAssociation
||
include
.
hasSingleAssociation
)
options
.
hasSingleAssociation
=
true
if
(
include
.
association
.
isSingleAssociation
||
include
.
hasSingleAssociation
)
options
.
hasSingleAssociation
=
true
...
...
lib/dialects/abstract/query.js
View file @
0b354f5
...
@@ -230,7 +230,14 @@ module.exports = (function() {
...
@@ -230,7 +230,14 @@ module.exports = (function() {
// Queries with include
// Queries with include
}
else
if
(
this
.
options
.
hasJoin
===
true
)
{
}
else
if
(
this
.
options
.
hasJoin
===
true
)
{
results
=
groupJoinData
(
results
,
this
.
options
)
results
=
groupJoinData
(
results
,
{
daoFactory
:
this
.
callee
,
includeMap
:
this
.
options
.
includeMap
,
includeNames
:
this
.
options
.
includeNames
},
{
checkExisting
:
this
.
options
.
hasMultiAssociation
})
result
=
results
.
map
(
function
(
result
)
{
result
=
results
.
map
(
function
(
result
)
{
return
this
.
callee
.
build
(
result
,
{
return
this
.
callee
.
build
(
result
,
{
isNewRecord
:
false
,
isNewRecord
:
false
,
...
@@ -328,26 +335,46 @@ module.exports = (function() {
...
@@ -328,26 +335,46 @@ module.exports = (function() {
]
]
*/
*/
var
groupJoinData
=
function
(
data
,
options
)
{
// includeOptions are 'level'-specific where options is a general directive
var
groupJoinData
=
function
(
data
,
includeOptions
,
options
)
{
var
results
=
[]
var
results
=
[]
,
existingResult
,
existingResult
,
calleeData
,
calleeData
,
child
,
child
,
calleeDataIgnore
=
[
'__children'
]
,
calleeDataIgnore
=
[
'__children'
]
,
parseChildren
=
function
(
result
)
{
_
.
each
(
result
.
__children
,
function
(
children
,
key
)
{
result
[
key
]
=
groupJoinData
(
children
,
(
includeOptions
.
includeMap
&&
includeOptions
.
includeMap
[
key
]),
options
)
})
delete
result
.
__children
},
primaryKeyAttribute
// Identify singular primaryKey attribute for equality check (if possible)
if
(
includeOptions
.
daoFactory
.
primaryKeyAttributes
.
length
===
1
)
{
primaryKeyAttribute
=
includeOptions
.
daoFactory
.
primaryKeyAttributes
[
0
]
}
else
if
(
includeOptions
.
daoFactory
.
rawAttributes
.
id
)
{
primaryKeyAttribute
=
'id'
}
if
(
options
.
includeNames
)
{
// Ignore all include keys on main data
calleeDataIgnore
=
calleeDataIgnore
.
concat
(
options
.
includeNames
)
if
(
includeOptions
.
includeNames
)
{
calleeDataIgnore
=
calleeDataIgnore
.
concat
(
includeOptions
.
includeNames
)
}
}
data
.
forEach
(
function
(
row
)
{
data
.
forEach
(
function
(
row
)
{
row
=
Dot
.
transform
(
row
)
row
=
Dot
.
transform
(
row
)
calleeData
=
_
.
omit
(
row
,
calleeDataIgnore
)
calleeData
=
_
.
omit
(
row
,
calleeDataIgnore
)
existingResult
=
_
.
find
(
results
,
function
(
result
)
{
// If there are :M associations included we need to see if the main result of the row has already been identified
if
(
calleeDataIgnore
)
{
existingResult
=
options
.
checkExisting
&&
_
.
find
(
results
,
function
(
result
)
{
return
Utils
.
_
.
isEqual
(
_
.
omit
(
result
,
calleeDataIgnore
),
calleeData
)
// If we can, detect equality on the singular primary key
if
(
primaryKeyAttribute
)
{
return
result
[
primaryKeyAttribute
]
===
calleeData
[
primaryKeyAttribute
]
}
}
return
Utils
.
_
.
isEqual
(
result
,
calleeData
)
// If we can't identify on a singular primary key, do a full row equality check
return
Utils
.
_
.
isEqual
(
_
.
omit
(
result
,
calleeDataIgnore
),
calleeData
)
})
})
if
(
!
existingResult
)
{
if
(
!
existingResult
)
{
...
@@ -357,24 +384,32 @@ module.exports = (function() {
...
@@ -357,24 +384,32 @@ module.exports = (function() {
for
(
var
attrName
in
row
)
{
for
(
var
attrName
in
row
)
{
if
(
row
.
hasOwnProperty
(
attrName
))
{
if
(
row
.
hasOwnProperty
(
attrName
))
{
// Child if object, and is an child include
// Child if object, and is an child include
child
=
Object
(
row
[
attrName
])
===
row
[
attrName
]
&&
options
.
includeMap
&&
o
ptions
.
includeMap
[
attrName
]
child
=
Object
(
row
[
attrName
])
===
row
[
attrName
]
&&
includeOptions
.
includeMap
&&
includeO
ptions
.
includeMap
[
attrName
]
if
(
child
)
{
if
(
child
)
{
if
(
!
existingResult
.
__children
)
existingResult
.
__children
=
{}
// Make sure nested object is available
if
(
!
existingResult
.
__children
[
attrName
])
existingResult
.
__children
[
attrName
]
=
[]
if
(
!
existingResult
.
__children
)
{
existingResult
.
__children
=
{}
}
if
(
!
existingResult
.
__children
[
attrName
])
{
existingResult
.
__children
[
attrName
]
=
[]
}
existingResult
.
__children
[
attrName
].
push
(
row
[
attrName
])
existingResult
.
__children
[
attrName
].
push
(
row
[
attrName
])
}
}
}
}
}
}
// parseChildren in same loop if no duplicate values are possible
if
(
!
options
.
checkExisting
)
{
parseChildren
(
existingResult
)
}
})
})
results
.
forEach
(
function
(
result
)
{
// parseChildren after row parsing if duplicate values are possible
_
.
each
(
result
.
__children
,
function
(
children
,
key
)
{
if
(
options
.
checkExisting
)
{
result
[
key
]
=
groupJoinData
(
children
,
(
options
.
includeMap
&&
options
.
includeMap
[
key
]))
results
.
forEach
(
parseChildren
)
})
}
delete
result
.
__children
})
return
results
return
results
}
}
...
...
lib/query-interface.js
View file @
0b354f5
...
@@ -711,7 +711,13 @@ module.exports = (function() {
...
@@ -711,7 +711,13 @@ module.exports = (function() {
}
}
var
sql
=
this
.
QueryGenerator
.
selectQuery
(
tableName
,
options
,
factory
)
var
sql
=
this
.
QueryGenerator
.
selectQuery
(
tableName
,
options
,
factory
)
queryOptions
=
Utils
.
_
.
extend
({},
queryOptions
,
{
include
:
options
.
include
,
includeNames
:
options
.
includeNames
,
includeMap
:
options
.
includeMap
})
queryOptions
=
Utils
.
_
.
extend
({},
queryOptions
,
{
include
:
options
.
include
,
includeNames
:
options
.
includeNames
,
includeMap
:
options
.
includeMap
,
hasSingleAssociation
:
options
.
hasSingleAssociation
,
hasMultiAssociation
:
options
.
hasMultiAssociation
})
return
queryAndEmit
.
call
(
this
,
[
sql
,
factory
,
queryOptions
],
'select'
)
return
queryAndEmit
.
call
(
this
,
[
sql
,
factory
,
queryOptions
],
'select'
)
}
}
...
...
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