Document.prototype.hasChanged >= 1.1.0
Purpose
Has this document changed since it was initialized?
Flags
- Client
- This will also be available on the client-side, in the browser.
Syntax
Document#hasChanged
(
Stringname
);
When no parameters are given, it returns true if any field has changed
Parameters
name
- Optional name of the field to check. Omit to check all fields.
Return values
Boolean
True if any field has changed
Examples
Change any field
let page = await Model.get('Page').find('first');
// When you've just queried something, it'll return false
page.hasChanged() === false;
// Now change a field
page.title = 'This is another title';
// Now hasChanged() will return true
page.hasChanged() === true;
Check a specific field for change
// We just changed the title, so that returns true
page.hasChanged('title') === true;
// Other fields were not changed
page.hasChanged('body') === false;
Comments