Skip to content

Model Class

columns()

columns() — returns array

Available in: model Category: Miscellaneous Functions

Returns an array of columns names for the table associated with this class. Does not include calculated properties that will be generated by the Wheels ORM.

// 1. Get all column names for the User model
cols = model("User").columns();
// cols -> ["id", "firstName", "lastName", "email", "createdAt", "updatedAt", "deletedAt"]

// 2. Check whether a specific column exists in the table
cols = model("User").columns();
if (arrayFindNoCase(cols, "deletedAt")) {
    writeOutput("Soft-delete column is present");
}

// 3. Iterate over all columns and output their names
cols = model("User").columns();
for (col in cols) {
    writeOutput(col);
}