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

Method reload

src/model.js:4257–4279  ·  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

4255 * @returns {Promise<Model>}
4256 */
4257 async reload(options) {
4258 options = Utils.defaults({
4259 where: this.where()
4260 }, options, {
4261 include: this._options.include || undefined
4262 });
4263
4264 const reloaded = await this.constructor.findOne(options);
4265 if (!reloaded) {
4266 throw new sequelizeErrors.InstanceError(
4267 'Instance could not be reloaded because it does not exist anymore (find call returned null)'
4268 );
4269 }
4270 // update the internal options of the instance
4271 this._options = reloaded._options;
4272 // re-set instance values
4273 this.set(reloaded.dataValues, {
4274 raw: true,
4275 reset: true && !options.attributes
4276 });
4277
4278 return this;
4279 }
4280
4281 /**
4282 * 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