Migrator
createView()
Signature
Section titled “Signature”createView() — returns ViewDefinition
Available in: migration
Category: Migration Functions
Description
Section titled “Description”Creates a view definition object to store view properties Only available in a migration CFC
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | yes | — | Name of the view to change properties on |
Examples
Section titled “Examples”// 1. Create a simple database view that joins users and roles
v = createView(name="userRoles");
v.selectStatement(sql="SELECT u.id, u.firstName, u.lastName, r.name AS roleName FROM users u INNER JOIN roles r ON u.roleId = r.id");
v.create();
// 2. Create a view for active (non-deleted) users using method chaining
createView(name="activeUsers")
.selectStatement(sql="SELECT id, firstName, lastName, email FROM users WHERE deletedAt IS NULL")
.create();
// 3. Full up/down migration using createView and dropView
component extends="wheels.migrator.Migration" {
function up() {
createView(name="publishedArticles")
.selectStatement(sql="SELECT id, title, body, authorId, publishedAt FROM articles WHERE publishedAt IS NOT NULL")
.create();
}
function down() {
dropView(name="publishedArticles");
}
}