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 ee7099a6
authored
Apr 21, 2015
by
Ruben Bridgewater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix instance.removeAssociation to fire the same select query twice
Use filter
1 parent
bb096ffb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
74 deletions
changelog.md
lib/associations/belongs-to-many.js
test/integration/associations/belongs-to-many.test.js
changelog.md
View file @
ee7099a
...
...
@@ -17,6 +17,11 @@
+
inflection@1.6.0
+
lodash@3.5.0
+
validator@3.34
+
generic-pool@2.2.0
-
[
INTERNALS
]
Updated devDependencies.
+
coffee-script@1.9.1
+
dox@0.7.1
+
mysql@2.6.2
# 2.0.5
-
[
FEATURE
]
Highly experimental support for nested creation
[
#3386
](
https://github.com/sequelize/sequelize/pull/3386
)
...
...
lib/associations/belongs-to-many.js
View file @
ee7099a
...
...
@@ -417,10 +417,27 @@ module.exports = (function() {
obj
[
this
.
accessors
.
set
]
=
function
(
newAssociatedObjects
,
options
)
{
options
=
options
||
{};
var
instance
=
this
;
return
instance
[
association
.
accessors
.
get
]({},
{
transaction
:
options
.
transaction
,
logging
:
options
.
logging
}).
then
(
function
(
oldAssociatedObjects
)
{
var
foreignIdentifier
=
association
.
foreignIdentifier
,
sourceKeys
=
Object
.
keys
(
association
.
source
.
primaryKeys
)
,
targetKeys
=
Object
.
keys
(
association
.
target
.
primaryKeys
)
,
obsoleteAssociations
=
[]
,
changedAssociations
=
[]
,
defaultAttributes
=
options
,
promises
=
[]
,
unassociatedObjects
;
if
(
newAssociatedObjects
===
null
)
{
newAssociatedObjects
=
[];
}
else
{
if
(
!
Array
.
isArray
(
newAssociatedObjects
))
{
newAssociatedObjects
=
[
newAssociatedObjects
];
}
newAssociatedObjects
=
newAssociatedObjects
.
map
(
function
(
newAssociatedObject
)
{
if
(
!
(
newAssociatedObject
instanceof
association
.
target
.
Instance
))
{
var
tmpInstance
=
{};
...
...
@@ -433,20 +450,10 @@ module.exports = (function() {
});
}
var
instance
=
this
;
return
instance
[
association
.
accessors
.
get
]({},
{
transaction
:
options
.
transaction
,
logging
:
options
.
logging
}).
then
(
function
(
oldAssociatedObjects
)
{
var
foreignIdentifier
=
association
.
foreignIdentifier
,
sourceKeys
=
Object
.
keys
(
association
.
source
.
primaryKeys
)
,
targetKeys
=
Object
.
keys
(
association
.
target
.
primaryKeys
)
,
obsoleteAssociations
=
[]
,
changedAssociations
=
[]
,
defaultAttributes
=
options
,
promises
=
[]
,
unassociatedObjects
;
if
(
options
.
remove
)
{
oldAssociatedObjects
=
newAssociatedObjects
;
newAssociatedObjects
=
[];
}
// Don't try to insert the transaction as an attribute in the through table
defaultAttributes
=
Utils
.
_
.
omit
(
defaultAttributes
,
[
'transaction'
,
'hooks'
,
'individualHooks'
,
'ignoreDuplicates'
,
'validate'
,
'fields'
,
'logging'
]);
...
...
@@ -704,62 +711,10 @@ module.exports = (function() {
}
};
obj
[
this
.
accessors
.
remove
]
=
function
(
oldAssociatedObject
,
options
)
{
var
instance
=
this
;
return
instance
[
association
.
accessors
.
get
]({},
options
).
then
(
function
(
currentAssociatedObjects
)
{
var
newAssociations
=
[];
if
(
!
(
oldAssociatedObject
instanceof
association
.
target
.
Instance
))
{
var
tmpInstance
=
{};
tmpInstance
[
primaryKeyAttribute
]
=
oldAssociatedObject
;
oldAssociatedObject
=
association
.
target
.
build
(
tmpInstance
,
{
isNewRecord
:
false
});
}
currentAssociatedObjects
.
forEach
(
function
(
association
)
{
if
(
!
Utils
.
_
.
isEqual
(
oldAssociatedObject
.
identifiers
,
association
.
identifiers
))
{
newAssociations
.
push
(
association
);
}
});
return
instance
[
association
.
accessors
.
set
](
newAssociations
,
options
);
});
};
obj
[
this
.
accessors
.
removeMultiple
]
=
function
(
oldAssociatedObjects
,
options
)
{
var
instance
=
this
;
return
instance
[
association
.
accessors
.
get
]({},
options
).
then
(
function
(
currentAssociatedObjects
)
{
var
newAssociations
=
[];
// Ensure the oldAssociatedObjects array is an array of target instances
oldAssociatedObjects
=
oldAssociatedObjects
.
map
(
function
(
oldAssociatedObject
)
{
if
(
!
(
oldAssociatedObject
instanceof
association
.
target
.
Instance
))
{
var
tmpInstance
=
{};
tmpInstance
[
primaryKeyAttribute
]
=
oldAssociatedObject
;
oldAssociatedObject
=
association
.
target
.
build
(
tmpInstance
,
{
isNewRecord
:
false
});
}
return
oldAssociatedObject
;
});
currentAssociatedObjects
.
forEach
(
function
(
association
)
{
// Determine is this is an association we want to remove
var
obj
=
Utils
.
_
.
find
(
oldAssociatedObjects
,
function
(
oldAssociatedObject
)
{
return
Utils
.
_
.
isEqual
(
oldAssociatedObject
.
identifiers
,
association
.
identifiers
);
});
// This is not an association we want to remove. Add it back
// to the set of associations we will associate our instance with
if
(
!
obj
)
{
newAssociations
.
push
(
association
);
}
});
return
instance
[
association
.
accessors
.
set
](
newAssociations
,
options
);
});
obj
[
this
.
accessors
.
removeMultiple
]
=
obj
[
this
.
accessors
.
remove
]
=
function
(
oldAssociatedObject
,
options
)
{
options
=
options
||
{};
options
.
remove
=
true
;
return
this
[
association
.
accessors
.
set
](
oldAssociatedObject
,
options
);
};
return
this
;
...
...
test/integration/associations/belongs-to-many.test.js
View file @
ee7099a
...
...
@@ -1134,10 +1134,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
expect
(
project
).
to
.
be
.
ok
;
return
self
.
user
.
removeProject
(
project
,
{
logging
:
function
(
sql
)
{
console
.
error
(
sql
);
spy
();
}
logging
:
spy
}).
return
(
project
);
}).
then
(
function
(
project
)
{
expect
(
spy
.
calledTwice
).
to
.
be
.
ok
;
// Once for SELECT, once for REMOVE
...
...
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