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 06d0b64b
authored
Mar 25, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check existing via a map instead of a lodash.find
1 parent
93b0daa1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
15 deletions
lib/dialects/abstract/query.js
lib/dialects/abstract/query.js
View file @
06d0b64
...
...
@@ -350,14 +350,8 @@ module.exports = (function() {
})
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'
}
primaryKeyAttribute
=
includeOptions
.
daoFactory
.
primaryKeyAttribute
,
primaryKeyMap
=
{}
// Ignore all include keys on main data
if
(
includeOptions
.
includeNames
)
{
...
...
@@ -369,18 +363,23 @@ module.exports = (function() {
calleeData
=
_
.
omit
(
row
,
calleeDataIgnore
)
// 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 we can, detect equality on the singular primary key
if
(
options
.
checkExisting
)
{
if
(
primaryKeyAttribute
)
{
return
result
[
primaryKeyAttribute
]
===
calleeData
[
primaryKeyAttribute
]
// If we can, detect equality on the singular primary key
existingResult
=
primaryKeyMap
[
calleeData
[
primaryKeyAttribute
]]
}
else
{
// If we can't identify on a singular primary key, do a full row equality check
existingResult
=
_
.
find
(
results
,
function
(
result
)
{
return
Utils
.
_
.
isEqual
(
_
.
omit
(
result
,
calleeDataIgnore
),
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
)
{
results
.
push
(
existingResult
=
calleeData
)
if
(
primaryKeyAttribute
)
{
primaryKeyMap
[
existingResult
[
primaryKeyAttribute
]]
=
existingResult
}
}
for
(
var
attrName
in
row
)
{
...
...
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