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 c3fe9efb
authored
Feb 17, 2013
by
Ricardo Graça
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable reusing query option objects in find
1 parent
bae5c971
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
19 deletions
lib/dao-factory.js
spec/dao.spec.js
lib/dao-factory.js
View file @
c3fe9ef
...
@@ -176,7 +176,7 @@ module.exports = (function() {
...
@@ -176,7 +176,7 @@ module.exports = (function() {
}
}
DAOFactory
.
prototype
.
find
=
function
(
options
)
{
DAOFactory
.
prototype
.
find
=
function
(
options
)
{
var
hasJoin
=
false
;
var
hasJoin
=
false
// no options defined?
// no options defined?
// return an emitter which emits null
// return an emitter which emits null
if
([
null
,
undefined
].
indexOf
(
options
)
!==
-
1
)
{
if
([
null
,
undefined
].
indexOf
(
options
)
!==
-
1
)
{
...
@@ -185,7 +185,7 @@ module.exports = (function() {
...
@@ -185,7 +185,7 @@ module.exports = (function() {
}).
run
()
}).
run
()
}
}
var
primaryKeys
=
this
.
primaryKeys
;
var
primaryKeys
=
this
.
primaryKeys
// options is not a hash but an id
// options is not a hash but an id
if
(
typeof
options
===
'number'
)
{
if
(
typeof
options
===
'number'
)
{
...
@@ -201,30 +201,34 @@ module.exports = (function() {
...
@@ -201,30 +201,34 @@ module.exports = (function() {
})
})
options
=
{
where
:
where
}
options
=
{
where
:
where
}
}
else
if
(
(
typeof
options
===
'string'
)
&&
(
parseInt
(
options
,
10
).
toString
()
===
options
)
)
{
}
else
if
(
typeof
options
===
'string'
&&
parseInt
(
options
,
10
).
toString
()
===
options
)
{
var
parsedId
=
parseInt
(
options
,
10
)
;
var
parsedId
=
parseInt
(
options
,
10
)
if
(
!
Utils
.
_
.
isFinite
(
parsedId
))
{
if
(
!
Utils
.
_
.
isFinite
(
parsedId
))
{
throw
new
Error
(
'Invalid argument to find(). Must be an id or an options object.'
)
throw
new
Error
(
'Invalid argument to find(). Must be an id or an options object.'
)
}
}
options
=
{
where
:
parsedId
}
options
=
{
where
:
parsedId
}
}
else
if
((
typeof
options
===
'object'
)
&&
(
options
.
hasOwnProperty
(
'include'
)))
{
}
else
if
(
typeof
options
===
'object'
)
{
var
includes
=
options
.
include
var
options
=
Utils
.
_
.
clone
(
options
)
hasJoin
=
true
;
var
includes
options
.
include
=
{}
if
(
options
.
hasOwnProperty
(
'include'
))
{
hasJoin
=
true
includes
.
forEach
(
function
(
daoName
)
{
includes
=
options
.
include
options
.
include
[
daoName
]
=
this
.
daoFactoryManager
.
getDAO
(
daoName
)
options
.
include
=
{}
if
(
!
options
.
include
[
daoName
])
{
includes
.
forEach
(
function
(
daoName
)
{
options
.
include
[
daoName
]
=
this
.
getAssociationByAlias
(
daoName
).
target
options
.
include
[
daoName
]
=
this
.
daoFactoryManager
.
getDAO
(
daoName
)
}
}.
bind
(
this
));
if
(
!
options
.
include
[
daoName
])
{
options
.
include
[
daoName
]
=
this
.
getAssociationByAlias
(
daoName
).
target
}
}.
bind
(
this
))
}
// whereCollection is used for
non-primary key updates
// whereCollection is used for non-primary key updates
this
.
options
.
whereCollection
=
options
.
where
||
null
;
this
.
options
.
whereCollection
=
options
.
where
||
null
}
}
options
.
limit
=
1
options
.
limit
=
1
...
...
spec/dao.spec.js
View file @
c3fe9ef
...
@@ -184,4 +184,21 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
...
@@ -184,4 +184,21 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
}.
bind
(
this
))
}.
bind
(
this
))
})
})
})
})
describe
(
'find'
,
function
find
()
{
it
(
"can reuse query option objects"
,
function
(
done
)
{
this
.
User
.
create
({
username
:
'fnord'
}).
success
(
function
()
{
var
query
=
{
where
:
{
username
:
'fnord'
}}
this
.
User
.
find
(
query
).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'fnord'
)
this
.
User
.
find
(
query
).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'fnord'
)
done
()
}.
bind
(
this
))
}.
bind
(
this
))
}.
bind
(
this
))
})
})
})
})
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