Reload a model's data from the database. ```js let post = blogPosts.find(1); post.attrs; // {id: 1, title: 'Lorem ipsum'} post.title = 'Hipster ipsum'; post.title; // 'Hipster ipsum'; post.reload(); // true post.title; // 'Lorem ipsum' ``` @method
()
| 273 | @public |
| 274 | */ |
| 275 | reload() { |
| 276 | if (this.id) { |
| 277 | let collection = this._schema.toInternalCollectionName(this.modelName); |
| 278 | let attrs = this._schema.db[collection].find(this.id); |
| 279 | |
| 280 | Object.keys(attrs) |
| 281 | .filter(function (attr) { |
| 282 | return attr !== "id"; |
| 283 | }) |
| 284 | .forEach(function (attr) { |
| 285 | this.attrs[attr] = attrs[attr]; |
| 286 | }, this); |
| 287 | } |
| 288 | |
| 289 | // Clear temp associations |
| 290 | this._tempAssociations = {}; |
| 291 | |
| 292 | return this; |
| 293 | } |
| 294 | |
| 295 | toJSON() { |
| 296 | return { ...this.attrs }; |
no test coverage detected