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 43152a2a
authored
Jul 13, 2013
by
Daniel Durante
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added smartWhere as a first class citizen to hasOne.
1 parent
a3051370
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
lib/associations/has-one.js
spec/associations/has-one.spec.js
lib/associations/has-one.js
View file @
43152a2
...
@@ -56,6 +56,12 @@ module.exports = (function() {
...
@@ -56,6 +56,12 @@ module.exports = (function() {
params
=
{
where
:
where
}
params
=
{
where
:
where
}
}
}
smart
=
Utils
.
smartWhere
([
where
,
params
.
where
||
[]],
self
.
target
.
daoFactoryManager
.
sequelize
.
options
.
dialect
)
smart
=
Utils
.
compileSmartWhere
.
call
(
self
.
target
,
smart
)
if
(
smart
.
length
>
0
)
{
params
.
where
=
smart
}
return
self
.
target
.
find
(
params
)
return
self
.
target
.
find
(
params
)
}
}
...
...
spec/associations/has-one.spec.js
View file @
43152a2
...
@@ -19,6 +19,27 @@ describe(Helpers.getTestDialectTeaser("HasOne"), function() {
...
@@ -19,6 +19,27 @@ describe(Helpers.getTestDialectTeaser("HasOne"), function() {
})
})
})
})
describe
(
'getAssocation'
,
function
()
{
it
(
'should be able to handle a where object that\'s a first class citizen.'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserXYZ'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'TaskXYZ'
,
{
title
:
Sequelize
.
STRING
,
status
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
,
status
:
'inactive'
}).
success
(
function
(
task
)
{
user
.
setTaskXYZ
(
task
).
success
(
function
()
{
user
.
getTaskXYZ
({
where
:
[
'status = ?'
,
'active'
]}).
success
(
function
(
task
)
{
expect
(
task
).
toEqual
(
null
)
done
()
})
})
})
})
})
})
})
describe
(
'setAssociation'
,
function
()
{
describe
(
'setAssociation'
,
function
()
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserXYZ'
,
{
username
:
Sequelize
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'UserXYZ'
,
{
username
:
Sequelize
.
STRING
})
...
...
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