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