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