Skip to content

Model Class

propertyNames()

propertyNames() — returns string

Available in: model Category: Miscellaneous Functions

Returns a list of all property names associated with a model. The list is ordered by the columns’ ordinal positions as they exist in the underlying database table. In addition to actual table columns, the list also includes any calculated properties defined through the property(), method, which may be derived from SQL expressions or mapped column names. This is useful when you need to dynamically work with all of a model’s attributes without hardcoding them, such as generating dynamic forms, building custom serializers, or inspecting ORM mappings.

1. Get property names for the User model
propNames = model("user").propertyNames();
writeOutput(propNames);

2. Loop through property names
for (prop in listToArray(model("employee").propertyNames())) {
    writeOutput("Property: #prop#<br>");
}

3. Check if a property exists in the list
if (listFindNoCase(model("order").propertyNames(), "totalAmount")) {
    writeOutput("Order model has a totalAmount property.");
}

4. Including calculated properties
// In the model configuration:
property(name="fullName", sql="firstName + ' ' + lastName");

// propertyNames() will now include "fullName"
writeOutput(model("user").propertyNames());