Model Object
hasProperty()
Signature
Section titled “Signature”hasProperty() — returns boolean
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Checks if a given property exists on a model object. It’s useful for safely validating whether a field is defined before accessing it, especially in dynamic code or when working with user input. This method also provides dynamic helpers (e.g., object.hasEmail()) for convenience.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
property | string | yes | — | Name of property to inspect. |
Examples
Section titled “Examples”1. Basic usage with existing property
employee = model("employee").new();
employee.firstName = "Alice";
writeOutput(employee.hasProperty("firstName")); // true
2. Checking a property that does not exist
employee = model("employee").new();
writeOutput(employee.hasProperty("middleName")); // false
3. Using the dynamic helper
employee = model("employee").new();
employee.email = "alice@example.com";
// Equivalent to hasProperty("email")
if (employee.hasEmail()) {
writeOutput("Email property exists!");
}
4. Before using a property safely
user = model("user").findByKey(1);
// Avoid runtime errors by checking
if (user.hasProperty("phoneNumber")) {
writeOutput(user.phoneNumber);
} else {
writeOutput("No phone number property defined.");
}