Skip to content

Model Configuration

property()

property() — returns void

Available in: model Category: Miscellaneous Functions

Lets you customize how model properties map to database columns or SQL expressions. By default, Wheels automatically maps a model’s property name to the column with the same name in the table. However, when your database uses non-standard column names, calculated values, or requires custom behavior, you can use property() to override the default mapping.

NameTypeRequiredDefaultDescription
namestringyesThe name that you want to use for the column or SQL function result in the CFML code.
columnstringnoThe name of the column in the database table to map the property to.
sqlstringnoAn SQL expression to use to calculate the property value.
labelstringnoA custom label for this property to be referenced in the interface and error messages.
defaultValuestringnoA default value for this property.
selectbooleannotrueWhether to include this property by default in SELECT statements
dataTypestringnocharSpecify the column dataType for this property
automaticValidationsbooleannoEnable / disable automatic validations for this property.
1. Tell Wheels that when we are referring to `firstName` in the CFML code, it should translate to the `STR_USERS_FNAME` column when interacting with the database instead of the default (which would be the `firstname` column)
property(name="firstName", column="STR_USERS_FNAME");

2. Tell Wheels that when we are referring to `fullName` in the CFML code, it should concatenate the `STR_USERS_FNAME` and `STR_USERS_LNAME` columns
property(name="fullName", sql="STR_USERS_FNAME + ' ' + STR_USERS_LNAME");

3. Tell Wheels that when displaying error messages or labels for form fields, we want to use `First name(s)` as the label for the `STR_USERS_FNAME` column
property(name="firstName", label="First name(s)");

4. Tell Wheels that when creating new objects, we want them to be auto-populated with a `firstName` property of value `Dave`
property(name="firstName", defaultValue="Dave");

5. Exclude property from SELECT queries
// Useful for virtual/computed properties you don’t want fetched from the DB
property(name="tempValue", select=false);

6. Override data type explicitly
property(name="isActive", dataType="boolean");