MCPcopy
hub / github.com/sequelize/sequelize / set

Method set

lib/model.js:3606–3736  ·  lib/model.js::Model.set

* Set is used to update values on the instance (the sequelize representation of the instance that is, remember that nothing will be persisted before you actually call `save`). * In its most basic form `set` will update a value stored in the underlying `dataValues` object. However, if a custom set

(key, value, options)

Source from the content-addressed store, hash-verified

3604 * @returns {Model}
3605 */
3606 set(key, value, options) {
3607 let values;
3608 let originalValue;
3609
3610 if (typeof key === class="st">'object' && key !== null) {
3611 values = key;
3612 options = value || {};
3613
3614 if (options.reset) {
3615 this.dataValues = {};
3616 for (const key in values) {
3617 this.changed(key, false);
3618 }
3619 }
3620
3621 class="cm">// If raw, and we're not dealing with includes or special attributes, just set it straight on the dataValues object
3622 if (options.raw && !(this._options && this._options.include) && !(options && options.attributes) && !this.constructor._hasDateAttributes && !this.constructor._hasBooleanAttributes) {
3623 if (Object.keys(this.dataValues).length) {
3624 Object.assign(this.dataValues, values);
3625 } else {
3626 this.dataValues = values;
3627 }
3628 class="cm">// If raw, .changed() shouldn't be true
3629 this._previousDataValues = { ...this.dataValues };
3630 } else {
3631 class="cm">// Loop and call set
3632 if (options.attributes) {
3633 const setKeys = data => {
3634 for (const k of data) {
3635 if (values[k] === undefined) {
3636 continue;
3637 }
3638 this.set(k, values[k], options);
3639 }
3640 };
3641 setKeys(options.attributes);
3642 if (this.constructor._hasVirtualAttributes) {
3643 setKeys(this.constructor._virtualAttributes);
3644 }
3645 if (this._options.includeNames) {
3646 setKeys(this._options.includeNames);
3647 }
3648 } else {
3649 for (const key in values) {
3650 this.set(key, values[key], options);
3651 }
3652 }
3653
3654 if (options.raw) {
3655 class="cm">// If raw, .changed() shouldn't be true
3656 this._previousDataValues = { ...this.dataValues };
3657 }
3658 }
3659 return this;
3660 }
3661 if (!options)
3662 options = {};
3663 if (!options.raw) {

Callers 6

_initValuesMethod · 0.95
refreshAttributesMethod · 0.95
setKeysMethod · 0.95
setAttributesMethod · 0.95
reloadMethod · 0.95
updateMethod · 0.95

Calls 5

changedMethod · 0.95
_setIncludeMethod · 0.95
getMethod · 0.65
setMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected