Model Class
tableName()
Signature
Section titled “Signature”tableName() — returns string
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Returns the name of the database table that this model is mapped to.
This is a getter and takes no arguments — the table setter is table().
Calling tableName() with an argument has always been a silent no-op (CFML
accepts the extra argument and the model keeps its convention table), a trap
some 4.0-era docs taught as a setter. When error information is shown
(development / testing, i.e. showErrorInformation) it now fails
loud; in production it stays a no-op so an upgrade never breaks a running
app. See issue #3079.
Examples
Section titled “Examples”// 1. Check what table the User model is mapped to (Wheels convention: singular model -> plural table)
name = model("User").tableName();
// name -> "users"
// 2. Check the table for a model that uses a custom table name (set via table() in config())
// In models/StaffMember.cfc: table("employees");
name = model("StaffMember").tableName();
// name -> "employees"
// 3. Use the table name dynamically in a log message or custom SQL fragment
tableUsed = model("Order").tableName();
writeOutput("Querying table: " & tableUsed);
// Outputs: Querying table: orders