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 e2777690
authored
Sep 03, 2013
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly copy the options objects passed to find and findall
1 parent
4dbb571f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletions
lib/dao-factory.js
test/dao-factory.test.js
lib/dao-factory.js
View file @
e277769
...
...
@@ -324,7 +324,8 @@ module.exports = (function() {
DAOFactory
.
prototype
.
findAll
=
function
(
options
,
queryOptions
)
{
var
hasJoin
=
false
var
options
=
Utils
.
_
.
clone
(
options
)
var
options
=
optClone
(
options
)
if
(
typeof
options
===
'object'
)
{
if
(
options
.
hasOwnProperty
(
'include'
))
{
...
...
@@ -367,6 +368,8 @@ module.exports = (function() {
DAOFactory
.
prototype
.
find
=
function
(
options
,
queryOptions
)
{
var
hasJoin
=
false
options
=
optClone
(
options
)
// no options defined?
// return an emitter which emits null
if
([
null
,
undefined
].
indexOf
(
options
)
!==
-
1
)
{
...
...
@@ -804,6 +807,13 @@ module.exports = (function() {
return
attributes
}
var
optClone
=
function
(
options
)
{
return
Utils
.
_
.
cloneDeep
(
options
,
function
(
elem
)
{
// The DAOFactories used for include are pass by ref, so don't clone them. Otherwise return undefined, meaning, 'handle this lodash'
return
elem
instanceof
DAOFactory
?
elem
:
undefined
})
}
Utils
.
_
.
extend
(
DAOFactory
.
prototype
,
require
(
"./associations/mixin"
))
return
DAOFactory
...
...
test/dao-factory.test.js
View file @
e277769
...
...
@@ -1441,6 +1441,15 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it
(
'does not modify the passed arguments'
,
function
(
done
)
{
var
options
=
{
where
:
[
'specialKey = ?'
,
'awesome'
]}
this
.
UserPrimary
.
find
(
options
).
success
(
function
(
user
)
{
expect
(
options
).
to
.
deep
.
equal
({
where
:
[
'specialKey = ?'
,
'awesome'
]})
done
()
})
})
it
(
'doesn\'t throw an error when entering in a non integer value for a specified primary field'
,
function
(
done
)
{
this
.
UserPrimary
.
find
(
'a string'
).
success
(
function
(
user
)
{
expect
(
user
.
specialKey
).
to
.
equal
(
'a string'
)
...
...
@@ -2458,6 +2467,15 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it
(
'does not modify the passed arguments'
,
function
(
done
)
{
var
options
=
{
where
:
[
'username = ?'
,
'awesome'
]}
this
.
User
.
findAll
(
options
).
success
(
function
(
user
)
{
expect
(
options
).
to
.
deep
.
equal
({
where
:
[
'username = ?'
,
'awesome'
]})
done
()
})
})
it
(
"finds all users matching the passed conditions"
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
"id != "
+
this
.
users
[
1
].
id
}).
success
(
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
1
)
...
...
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