MCPcopy
hub / github.com/sequelize/sequelize / reload

Method reload

lib/model.js:4122–4144  ·  view source on GitHub ↗

* Refresh the current instance in-place, i.e. update the object with current data from the DB and return the same object. * This is different from doing a `find(Instance.id)`, because that would create and return a new instance. With this method, * all references to the Instance are updated wi

(options)

Source from the content-addressed store, hash-verified

4120 * @returns {Promise<Model>}
4121 */
4122 async reload(options) {
4123 options = Utils.defaults({
4124 where: this.where()
4125 }, options, {
4126 include: this._options.include || undefined
4127 });
4128
4129 const reloaded = await this.constructor.findOne(options);
4130 if (!reloaded) {
4131 throw new sequelizeErrors.InstanceError(
4132 'Instance could not be reloaded because it does not exist anymore (find call returned null)'
4133 );
4134 }
4135 // update the internal options of the instance
4136 this._options = reloaded._options;
4137 // re-set instance values
4138 this.set(reloaded.dataValues, {
4139 raw: true,
4140 reset: true && !options.attributes
4141 });
4142
4143 return this;
4144 }
4145
4146 /**
4147 * Validate the attributes of this instance according to validation rules set in the model definition.

Callers 15

schema.test.jsFile · 0.80
data-types.test.jsFile · 0.80
model.test.jsFile · 0.80
sequelize.test.jsFile · 0.80
instance.test.jsFile · 0.80
dao.test.jsFile · 0.80
has-one.test.jsFile · 0.80
has-many.test.jsFile · 0.80
belongs-to.test.jsFile · 0.80
update.test.jsFile · 0.80
field.test.jsFile · 0.80

Calls 3

whereMethod · 0.95
setMethod · 0.95
findOneMethod · 0.80

Tested by

no test coverage detected