Model Generator
The model generator creates CQL ORM models for your Azu application. Models represent database tables and provide an object-oriented interface for database operations.
Overview
azu generate model <name> [field:type] [options]Basic Usage
Generate a Simple Model
# Generate a basic model
azu generate model user
# Generate with fields
azu generate model user name:string email:string age:integer
# Generate with relationships
azu generate model post title:string content:text user:referencesGenerate with Validations
# Generate model with common validations
azu generate model user name:string email:string --validations
# Generate with timestamps
azu generate model post title:string content:text --timestamps
# Generate with UUID primary key
azu generate model user name:string email:string --uuidCommand Options
--validations
Add common validations
false
--timestamps
Add created_at/updated_at fields
false
--uuid
Use UUID as primary key
false
--skip-tests
Don't generate test files
false
--skip-migration
Don't generate migration file
false
--force
Overwrite existing files
false
Field Types
string
String
VARCHAR(255)
Short text field
text
String
TEXT
Long text field
integer
Int32
INTEGER
32-bit integer
bigint
Int64
BIGINT
64-bit integer
float
Float64
FLOAT
Floating point number
decimal
BigDecimal
DECIMAL
Precise decimal number
boolean
Bool
BOOLEAN
True/false value
date
Date
DATE
Date only
time
Time
TIMESTAMP
Date and time
json
JSON::Any
JSON/JSONB
JSON data
uuid
UUID
UUID
UUID field
references
Int64
BIGINT
Foreign key reference
Generated Files
Model File
Migration File
Test File
Examples
User Model
Generated Model:
Post Model with Relationships
Generated Model:
Category Model with UUID
Generated Model:
Relationships
Belongs To
Has Many
Many to Many
Validations
Common Validations
Generated Validations:
Custom Validations
Scopes and Class Methods
Generated Scopes
Instance Methods
Advanced Usage
Polymorphic Associations
STI (Single Table Inheritance)
Custom Field Types
Testing
Model Tests
Best Practices
1. Naming Conventions
2. Field Types
3. Validations
4. Relationships
5. Performance
Troubleshooting
Migration Issues
Model Issues
Validation Issues
The model generator creates CQL ORM models with proper validations, relationships, and database migrations for your Azu application.
Next Steps:
Migration Generator - Create database migrations
Endpoint Generator - Create HTTP endpoints
Service Generator - Create business logic services
Last updated