MCPcopy
hub / github.com/sequelize/sequelize / remove

Method remove

lib/associations/has-many.js:435–452  ·  view source on GitHub ↗

* Un-associate one or several target rows. * * @param {Model} sourceInstance instance to un associate instances with * @param {Model|Model[]|string|string[]|number|number[]} [targetInstances] Can be an Instance or its primary key, or a mixed array of instances and primary keys * @param {

(sourceInstance, targetInstances, options = {})

Source from the content-addressed store, hash-verified

433 * @returns {Promise}
434 */
435 async remove(sourceInstance, targetInstances, options = {}) {
436 const update = {
437 [this.foreignKey]: null
438 };
439
440 targetInstances = this.toInstanceArray(targetInstances);
441
442 const where = {
443 [this.foreignKey]: sourceInstance.get(this.sourceKey),
444 [this.target.primaryKeyAttribute]: targetInstances.map(targetInstance =>
445 targetInstance.get(this.target.primaryKeyAttribute)
446 )
447 };
448
449 await this.target.unscoped().update(update, { ...options, where });
450
451 return this;
452 }
453
454 /**
455 * Create a new instance of the associated model and associate it with this.

Callers 5

saveMethod · 0.45
menu-groups.jsFile · 0.45
groupDataTypesFunction · 0.45

Calls 4

toInstanceArrayMethod · 0.80
unscopedMethod · 0.80
getMethod · 0.65
updateMethod · 0.45

Tested by

no test coverage detected