MCPcopy
hub / github.com/miragejs/miragejs / reload

Method reload

lib/orm/model.js:275–293  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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 };

Calls 3

findMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected