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

Method remove

lib/associations/belongs-to-many.js:764–777  ·  view source on GitHub ↗

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

(sourceInstance, oldAssociatedObjects, options)

Source from the content-addressed store, hash-verified

762 * @returns {Promise}
763 */
764 remove(sourceInstance, oldAssociatedObjects, options) {
765 const association = this;
766
767 options = options || {};
768
769 oldAssociatedObjects = association.toInstanceArray(oldAssociatedObjects);
770
771 const where = {
772 [association.identifier]: sourceInstance.get(association.sourceKey),
773 [association.foreignIdentifier]: oldAssociatedObjects.map(newInstance => newInstance.get(association.targetKey))
774 };
775
776 return association.through.model.destroy({ ...options, where });
777 }
778
779 /**
780 * Create a new instance of the associated model and associate it with this.

Callers

nothing calls this directly

Calls 3

toInstanceArrayMethod · 0.80
destroyMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected