What problem does it solve?
This Skill simplifies the creation of CFWheels ORM models, ensuring proper validations, associations, and methods while preventing common Wheels-specific errors like mixed argument styles and missing primary key declarations. It provides a production-ready template to build reliable data layers.
Core Features & Use Cases
- ORM Model Generation: Creates models with
hasMany, belongsTo, hasManyThrough associations.
- Comprehensive Validations: Supports presence, uniqueness, format, length, numericality, confirmation, inclusion/exclusion, and custom validations.
- Lifecycle Callbacks: Implements
before/after callbacks for validation, save, create, update, and delete events.
- Critical Fixes: Includes mandatory fixes for
setPrimaryKey() and structKeyExists() checks in callbacks, preventing common runtime errors.
- Use Case: Create a
User model that hasMany Tweets and Likes, validates email format and password length, and hashes passwords before saving. This skill ensures all these features are implemented correctly and securely, saving you from common pitfalls.
Quick Start
Example Model:
component extends="Model" {
function config() {
setPrimaryKey("id"); # CRITICAL!
hasMany(name="comments", dependent="delete");
validatesPresenceOf(properties="title");
beforeCreate("setDefaults");
}
private function setDefaults() {
if (!structKeyExists(this, "count")) { this.count = 0; }
}
}