Model Class
columnForProperty()
Signature
Section titled “Signature”columnForProperty() — returns any
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Returns the column name mapped for the named model property.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
property | string | yes | — | Name of property to inspect. |
Examples
Section titled “Examples”// 1. Get the column name mapped to a model property
col = model("User").columnForProperty("firstName");
// col -> "first_name"
// 2. Check the column for a property before building a raw SQL fragment
col = model("Order").columnForProperty("placedAt");
if (col != false) {
writeOutput("Column in the database: " & col);
}
// 3. Returns false when the property does not exist on the model
col = model("User").columnForProperty("nonExistentProperty");
// col -> false