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

Method set

src/model.js:3732–3862  ·  view source on GitHub ↗

* 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

3730 * @returns {Model}
3731 */
3732 set(key, value, options) {
3733 let values;
3734 let originalValue;
3735
3736 if (typeof key === 'object' && key !== null) {
3737 values = key;
3738 options = value || {};
3739
3740 if (options.reset) {
3741 this.dataValues = {};
3742 for (const key in values) {
3743 this.changed(key, false);
3744 }
3745 }
3746
3747 // If raw, and we're not dealing with includes or special attributes, just set it straight on the dataValues object
3748 if (options.raw && !(this._options && this._options.include) && !(options && options.attributes) && !this.constructor._hasDateAttributes && !this.constructor._hasBooleanAttributes) {
3749 if (Object.keys(this.dataValues).length) {
3750 Object.assign(this.dataValues, values);
3751 } else {
3752 this.dataValues = values;
3753 }
3754 // If raw, .changed() shouldn't be true
3755 this._previousDataValues = { ...this.dataValues };
3756 } else {
3757 // Loop and call set
3758 if (options.attributes) {
3759 const setKeys = data => {
3760 for (const k of data) {
3761 if (values[k] === undefined) {
3762 continue;
3763 }
3764 this.set(k, values[k], options);
3765 }
3766 };
3767 setKeys(options.attributes);
3768 if (this.constructor._hasVirtualAttributes) {
3769 setKeys(this.constructor._virtualAttributes);
3770 }
3771 if (this._options.includeNames) {
3772 setKeys(this._options.includeNames);
3773 }
3774 } else {
3775 for (const key in values) {
3776 this.set(key, values[key], options);
3777 }
3778 }
3779
3780 if (options.raw) {
3781 // If raw, .changed() shouldn't be true
3782 this._previousDataValues = { ...this.dataValues };
3783 }
3784 }
3785 return this;
3786 }
3787 if (!options)
3788 options = {};
3789 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