The wheels generate model command creates a new model CFC file with optional properties, associations, and database migrations. Models represent database tables and contain business logic, validations, and relationships.
Arguments
Argument
Description
Default
name
Model name (singular)
Required
Options
Option
Description
Default
--migration
Generate database migration
true
properties
Model properties (format: name:type,name2:type2)
belongs-to
Parent model relationships (comma-separated)
has-many
Child model relationships (comma-separated)
has-one
One-to-one relationships (comma-separated)
primary-key
Primary key column name(s)
id
table-name
Custom database table name
description
Model description
--force
Overwrite existing files
false
Examples
Basic model
wheels generate model user
Creates:
/models/User.cfc
Migration file (if enabled)
Model with properties
wheels generate model user properties="firstName:string,lastName:string,email:string,age:integer"
Model with associations
wheels generate model post belongs-to="user" has-many="comments"
Model without migration
wheels generate model setting --migration=false
Complex model
wheels generate model product \
properties="name:string,price:decimal,stock:integer,active:boolean" \
belongs-to="category,brand" \
has-many="reviews,orderItems"
Property Types
Type
Database Type
CFML Type
string
VARCHAR(255)
string
text
TEXT
string
integer
INTEGER
numeric
biginteger
BIGINT
numeric
float
FLOAT
numeric
decimal
DECIMAL(10,2)
numeric
boolean
BOOLEAN
boolean
date
DATE
date
datetime
DATETIME
date
timestamp
TIMESTAMP
date
binary
BLOB
binary
uuid
VARCHAR(35)
string
Generated Code
Basic Model
component extends="Model" {
function init() {
// Table name (optional if following conventions)
table("users");
// Validations
validatesPresenceOf("email");
validatesUniquenessOf("email");
validatesFormatOf("email", regex="^[^@]+@[^@]+\.[^@]+$");
// Callbacks
beforeCreate("setDefaultValues");
}
private function setDefaultValues() {
if (!StructKeyExists(this, "createdAt")) {
this.createdAt = Now();
}
}
}