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 14cb25aa
authored
Jul 09, 2012
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hasMany properly uses omitNull option
1 parent
5d053be7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletions
lib/associations/has-many-single-linked.js
spec/associations/has-many.spec.js
lib/associations/has-many-single-linked.js
View file @
14cb25a
...
@@ -15,7 +15,7 @@ module.exports = (function() {
...
@@ -15,7 +15,7 @@ module.exports = (function() {
HasManySingleLinked
.
prototype
.
injectSetter
=
function
(
emitter
,
oldAssociations
,
newAssociations
)
{
HasManySingleLinked
.
prototype
.
injectSetter
=
function
(
emitter
,
oldAssociations
,
newAssociations
)
{
var
self
=
this
var
self
=
this
,
options
=
this
.
options
||
{}
,
options
=
this
.
__factory
.
options
// clear the old associations
// clear the old associations
oldAssociations
.
forEach
(
function
(
associatedObject
)
{
oldAssociations
.
forEach
(
function
(
associatedObject
)
{
...
...
spec/associations/has-many.spec.js
View file @
14cb25a
...
@@ -162,6 +162,33 @@ describe('HasMany', function() {
...
@@ -162,6 +162,33 @@ describe('HasMany', function() {
})
})
})
})
})
})
it
(
"clears associations when passing null to the set-method with omitNull set to true"
,
function
(
done
)
{
sequelize
.
options
.
omitNull
=
true
;
var
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
Task
.
hasMany
(
User
)
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
})
})
})
})
})
})
})
})
})
describe
(
'(N:M)'
,
function
()
{
describe
(
'(N:M)'
,
function
()
{
...
...
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