wheels generate scaffold
Generate complete CRUD scaffolding for a resource including model, controller, views, tests, and migration.
Synopsis
wheels generate scaffold name [options]
wheels g scaffold name [options]
wheels g resource name [options] # Alias for scaffoldDescription
The wheels scaffold command (alias: wheels g resource) generates a complete CRUD (Create, Read, Update, Delete) implementation including model, controller, views, tests, and database migration. It's the fastest way to create a fully functional resource.
CommandBox Parameter Syntax
This command supports multiple parameter formats:
Positional parameters:
wheels generate scaffold Product(resource name)Named parameters:
name=value(e.g.,name=Product,properties="name:string")Flag parameters:
--flagequalsflag=true(e.g.,--apiequalsapi=true)Flag with value:
--flag=value(e.g.,--properties="name:string")
Parameter Mixing Rules:
ALLOWED:
All positional:
wheels generate scaffold ProductAll named:
name=Product properties="name:string"Positional + flags:
wheels generate scaffold Product --api --migrate
NOT ALLOWED:
Positional + named:
wheels generate scaffold Product properties="name:string"(causes error)
Recommendation: Use positional for resource name, flags for options: wheels generate scaffold Product --properties="name:string" --api --migrate
Arguments
name
Resource name (singular)
Required
Options
--properties
Model properties (format: name:type,name2:type2)
--properties="name:string,price:decimal"
--belongsTo
Parent model relationships (comma-separated)
--belongsTo=User,Category
--hasMany
Child model relationships (comma-separated)
--hasMany=orders,comments
--api
Generate API-only scaffold (no views)
--api=true or --api
false
--tests
Generate test files
--tests=false
true
--migrate
Run migrations after scaffolding
--migrate=true or --migrate
false
--force
Overwrite existing files
--force=true or --force
false
Examples
Basic Examples
# Basic scaffold
wheels g scaffold Product
wheels g resource Product # Same as scaffold
# With properties
wheels g scaffold Product --properties="name:string,price:decimal,stock:integer"
wheels g resource Product --properties="name:string,price:decimal,stock:integer"
# With associations
wheels g scaffold Order --properties="total:decimal,status:string" --belongsTo=User --hasMany=orderItems
# API-only scaffold (no views)
wheels g scaffold Product --api --properties="name:string,price:decimal"
wheels g resource Product --api --properties="name:string,price:decimal"
# With auto-migration
wheels g scaffold Category --properties="name:string" --migrateAdvanced Examples
# Complete e-commerce product
wheels generate scaffold Product --properties="name:string,description:text,price:decimal,inStock:boolean" --belongsTo=Category --hasMany=orderItems,reviews --migrate
# Blog system
wheels generate scaffold Post --properties="title:string,content:text,published:boolean" --belongsTo=User --hasMany=comments --apiParameter Details
Properties Format:
Format:
--properties="name:type,name2:type2"Types:
string,text,integer,decimal,boolean,date,datetime,timeAlways use quotes around the entire properties string
Associations:
--belongsTo=Model1,Model2(PascalCase parent models)--hasMany=model1,model2(camelCase plural child models)
Resource Name:
Must be singular (e.g.,
Product, notProducts)PascalCase recommended (e.g.,
OrderItem,UserProfile)
What Gets Generated
Standard Scaffold
Model (
/models/Product.cfc) - Properties, validations, associationsController (
/controllers/Products.cfc) - All CRUD actions (index, show, new, create, edit, update, delete)Views (
/views/products/) - index, show, new, edit, _form partialMigration (
/app/migrator/migrations/[timestamp]_create_products.cfc) - Table creation with indexesTests - Model, controller, and integration tests (if
--tests=true)
API Scaffold
Model - Same as standard
API Controller - JSON responses only, no views
Migration - Same as standard
API Tests - JSON response tests
Generated Code Structure
For wheels scaffold Product --properties="name:string,price:decimal":
Model: Properties with validations (presence, uniqueness, numerical) Controller: Full CRUD actions with flash messages and error handling Views: List, show, new/edit forms with proper encoding and form helpers Migration: Table with columns, timestamps, and indexes
Run the command to see the complete generated code.
Routes Configuration
Add to /config/routes.cfm:
<cfset resources("products")>This creates all RESTful routes (index, new, create, show, edit, update, delete).
Post-Scaffold Steps
Run migration (if not using
--migrate):wheels dbmigrate latestAdd routes to
/config/routes.cfm:<cfset resources("products")>Reload application:
wheels reloadTest: Visit
/productsand test CRUD operations
Common Customizations
Search:
function index() {
products = StructKeyExists(params, "search")
? model("Product").findAll(where="name LIKE :search", params={search: "%#params.search#%"})
: model("Product").findAll();
}Pagination:
products = model("Product").findAll(page=params.page ?: 1, perPage=20);Authentication:
function init() {
filters(through="authenticate", except="index,show");
}Template Customization
Customize generated code by overriding templates:
Copy templates from
/cli/templates/to/app/snippets/Modify templates to match your project style
CLI uses your custom templates automatically
Available Templates:
crud/index.txt,crud/show.txt,crud/new.txt,crud/edit.txt,crud/_form.txtModelContent.txt,ControllerContent.txt
Template Placeholders:
|ObjectNameSingular|,|ObjectNamePlural|- Lowercase names|ObjectNameSingularC|,|ObjectNamePluralC|- Capitalized names|FormFields|- Generated form fields
Troubleshooting
Common Issues
Parameter Syntax Errors
❌ Wrong:
wheels generate scaffold Product properties="name:string" # Positional + named (ERROR)
wheels generate scaffold Product --properties=name:string # Missing quotes
wheels generate scaffold Comment --belongsTo=product # Wrong case (should be Product)✅ Correct:
wheels generate scaffold Product --properties="name:string,price:decimal"
wheels generate scaffold Comment --belongsTo=Product --hasMany=repliesRules:
Always use quotes around properties:
--properties="name:string"Use PascalCase for belongsTo:
--belongsTo=UserUse camelCase plural for hasMany:
--hasMany=posts,commentsNever mix positional and named parameters
File Generation Issues
Problem: Files not created or partially generated
Solutions:
Check directory permissions:
ls -la app/models app/controllersUse
--forceto overwrite existing filesUse singular PascalCase names (e.g.,
Product, notproductsorproduct-item)
Migration Issues
Problem: Migrations not created or contain errors
Solutions:
Use valid property types:
string,text,integer,decimal,boolean,date,datetimeCheck generated migration:
ls app/migrator/migrations/*create*Foreign keys are auto-generated for associations
Route Issues
Problem: Routes not working
Solution: Add resources to /config/routes.cfm:
<cfscript>
mapper()
.resources("products")
.wildcard()
.end();
</cfscript>Validation Checklist
Before scaffolding:
Verify Wheels directory structure exists
Check for naming conflicts
Plan properties and associations
After scaffolding:
Check files were created:
ls app/models/ app/controllers/ app/views/Run migrations:
wheels dbmigrate latestAdd routes to
routes.cfmTest at
/products
Best Practices
Plan First: Define properties, associations, and validations before scaffolding
Start Simple: Begin with basic properties, add complexity later
Use Templates: Customize templates in
/app/snippets/to match your project standardsTest Immediately: Run generated tests and visit the scaffold in browser
Security: Add authentication/authorization filters after generation
Incremental: Scaffold one resource at a time, test, then move to the next
See Also
wheels generate model - Generate models only
wheels generate controller - Generate controllers only
wheels generate view - Generate views only
wheels dbmigrate latest - Run migrations
Last updated
Was this helpful?

