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 d9debb39
authored
Feb 02, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove a concat from build() and fix tests
1 parent
9b22f127
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
19 deletions
lib/dao-factory.js
lib/dialects/abstract/query.js
lib/dao-factory.js
View file @
d9debb3
...
@@ -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
)
{
...
@@ -1343,6 +1334,7 @@ module.exports = (function() {
...
@@ -1343,6 +1334,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 @
d9debb3
...
@@ -230,7 +230,10 @@ module.exports = (function() {
...
@@ -230,7 +230,10 @@ 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
,
this
.
options
,
{
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,22 +331,24 @@ module.exports = (function() {
...
@@ -328,22 +331,24 @@ 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'
]
if
(
o
ptions
.
includeNames
)
{
if
(
includeO
ptions
.
includeNames
)
{
calleeDataIgnore
=
calleeDataIgnore
.
concat
(
o
ptions
.
includeNames
)
calleeDataIgnore
=
calleeDataIgnore
.
concat
(
includeO
ptions
.
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
=
options
.
hasMultiAssociation
&&
_
.
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
existingResult
=
options
.
checkExisting
&&
_
.
find
(
results
,
function
(
result
)
{
if
(
calleeDataIgnore
)
{
if
(
calleeDataIgnore
)
{
return
Utils
.
_
.
isEqual
(
_
.
omit
(
result
,
calleeDataIgnore
),
calleeData
)
return
Utils
.
_
.
isEqual
(
_
.
omit
(
result
,
calleeDataIgnore
),
calleeData
)
}
}
...
@@ -357,11 +362,16 @@ module.exports = (function() {
...
@@ -357,11 +362,16 @@ 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
])
}
}
...
@@ -371,7 +381,7 @@ module.exports = (function() {
...
@@ -371,7 +381,7 @@ module.exports = (function() {
results
.
forEach
(
function
(
result
)
{
results
.
forEach
(
function
(
result
)
{
_
.
each
(
result
.
__children
,
function
(
children
,
key
)
{
_
.
each
(
result
.
__children
,
function
(
children
,
key
)
{
result
[
key
]
=
groupJoinData
(
children
,
(
options
.
includeMap
&&
options
.
includeMap
[
key
])
)
result
[
key
]
=
groupJoinData
(
children
,
(
includeOptions
.
includeMap
&&
includeOptions
.
includeMap
[
key
]),
options
)
})
})
delete
result
.
__children
delete
result
.
__children
})
})
...
...
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