* 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 = {})
| 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. |
no test coverage detected