Model Object
hasChanged()
Signature
Section titled “Signature”hasChanged() — returns boolean
Available in: model
Category: Change Functions
Description
Section titled “Description”Returns true if the specified property (or any if none was passed in) has been changed but not yet saved to the database.
Will also return true if the object is new and no record for it exists in the database.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
property | string | no | — | Name of property to check for change. |
Examples
Section titled “Examples”1. Get a member object and change the `email` property on it
member = model("member").findByKey(params.memberId);
member.email = params.newEmail;
2. Check if the `email` property has changed
if(member.hasChanged("email")){
// Do something...
}
3. The above can also be done using a dynamic function like this
if(member.emailHasChanged()){
// Do something...
}