Skip to content

Model Object

changedFrom()

changedFrom() — returns string

Available in: model Category: Change Functions

Returns the previous value of a property that has changed. Returns an empty string if no previous value exists. Wheels will keep a note of the previous property value until the object is saved to the database.

NameTypeRequiredDefaultDescription
propertystringyes—Name of property to get the previous value for.
// 1. Get the previous value of a changed property
user = model("User").findByKey(params.userId);
user.email = params.newEmail;

// Returns the original email address before it was changed
oldEmail = user.changedFrom("email");
// oldEmail -> "original@example.com"

// 2. Use the dynamic shorthand method (equivalent to the above)
oldEmail = user.emailChangedFrom();

// 3. Check if a property changed before accessing the previous value
user = model("User").findByKey(params.userId);
user.firstName = params.firstName;

if (user.hasChanged("firstName")) {
	oldName = user.changedFrom("firstName");
	// oldName -> "Jane"
}
// Returns empty string if property has not changed or no previous value exists