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 e7521c4d
authored
Dec 29, 2013
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test and fix for removeHasManyDoubleLinkedAssociation
1 parent
ba58986d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletions
lib/associations/has-many-double-linked.js
test/associations/has-many.test.js
lib/associations/has-many-double-linked.js
View file @
e7521c4
...
...
@@ -121,9 +121,15 @@ module.exports = (function() {
if
(
!
newObj
)
{
obsoleteAssociations
.
push
(
old
)
}
else
if
(
Object
(
targetAssociation
.
through
)
===
targetAssociation
.
through
)
{
var
throughAttributes
=
newObj
[
self
.
association
.
through
.
name
];
// Quick-fix for subtle bug when using existing objects that might have the through model attached (not as an attribute object)
if
(
throughAttributes
instanceof
self
.
association
.
through
.
DAO
)
{
throughAttributes
=
{};
}
var
changedAssociation
=
{
where
:
{},
attributes
:
Utils
.
_
.
defaults
({},
newObj
[
self
.
association
.
through
.
name
]
,
defaultAttributes
)
attributes
:
Utils
.
_
.
defaults
({},
throughAttributes
,
defaultAttributes
)
}
changedAssociation
.
where
[
self
.
association
.
identifier
]
=
self
.
instance
[
self
.
association
.
identifier
]
||
self
.
instance
.
id
...
...
test/associations/has-many.test.js
View file @
e7521c4
...
...
@@ -886,6 +886,40 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
describe
(
'removing from the join table'
,
function
()
{
it
(
'should remove a single entry without any attributes (and timestamps off) on the through model'
,
function
(
done
)
{
var
Worker
=
this
.
sequelize
.
define
(
'Worker'
,
{},
{
timestamps
:
false
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{},
{
timestamps
:
false
})
,
WorkerTasks
=
this
.
sequelize
.
define
(
'WorkerTasks'
,
{},
{
timestamps
:
false
})
Worker
.
hasMany
(
Task
,
{
through
:
WorkerTasks
})
Task
.
hasMany
(
Worker
,
{
through
:
WorkerTasks
})
this
.
sequelize
.
sync
().
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
Worker
.
create
().
done
(
function
(
err
,
worker
)
{
expect
(
err
).
not
.
to
.
be
.
ok
Task
.
bulkCreate
([{},
{}]).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
Task
.
findAll
().
done
(
function
(
err
,
tasks
)
{
expect
(
err
).
not
.
to
.
be
.
ok
worker
.
setTasks
(
tasks
).
done
(
function
(
err
)
{
worker
.
removeTask
(
tasks
[
0
]).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
worker
.
getTasks
().
done
(
function
(
err
,
tasks
)
{
expect
(
tasks
.
length
).
to
.
equal
(
1
)
done
()
})
})
})
})
})
})
})
})
})
})
describe
(
'belongsTo and hasMany at once'
,
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