Skip to content

Commit 7146c7d

Browse files
committed
Merge pull request #320 from kvanwagenen/master
Fix for incorrect argument handling in delete accessor of Many association
2 parents 232bee6 + d2c1ff5 commit 7146c7d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/Associations/Many.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,22 @@ function extendInstance(Model, Instance, Driver, association, opts, createInstan
257257
});
258258
Object.defineProperty(Instance, association.delAccessor, {
259259
value: function () {
260-
var Associations = Array.prototype.slice.apply(arguments);
261-
var cb = (typeof Associations[Associations.length - 1] == "function" ? Associations.pop() : noOperation);
260+
var Associations = [];
261+
var cb = noOperation;
262+
for (var i = 0; i < arguments.length; i++) {
263+
switch (typeof arguments[i]) {
264+
case "function":
265+
cb = arguments[i];
266+
break;
267+
case "object":
268+
if (Array.isArray(arguments[i])) {
269+
Associations = Associations.concat(arguments[i]);
270+
} else if (arguments[i].isInstance) {
271+
Associations.push(arguments[i]);
272+
}
273+
break;
274+
}
275+
}
262276
var conditions = {};
263277
var run = function () {
264278
if (Driver.hasMany) {

0 commit comments

Comments
 (0)