Skip to content

generate model: emit validatesPresenceOf + type validations from attr specs #2219

Description

@bpamiri

Problem

Running:

wheels generate model User name:string email:string

produces a model with an empty `config()`:

component extends=\"Model\" {
    function config() {




    }
}

The attr specs (`name:string`, `email:string`) are dropped — the current `ModelContent.txt` template only fills in relationship scaffolds (`belongsToRelationships`, `hasManyRelationships`, `hasOneRelationships`), not validations or type hints.

Expected

The issue template in #2208 (and the docs in CLAUDE.md — Model Quick Reference) imply that typed attrs should round-trip into the model's `config()` as validations:

component extends=\"Model\" {
    function config() {
        validatesPresenceOf(\"name,email\");
        // maybe: validatesFormatOf(property=\"email\", regEx=\"...\") for type=email
    }
}

This matches Rails `rails generate model User name:string email:string` behavior and is what the ecosystem expects.

Discovered via

Adding the #2208 smoke test (#2217) — initially asserted `validatesPresenceOf` per #2208's example, failed, confirmed the generator doesn't emit it, weakened the assertion to just `extends="Model"` + `function config`. The smoke test now passes but the expectation gap remains.

Acceptance criteria

  • `wheels generate model Foo bar:string baz:integer` emits `validatesPresenceOf("bar,baz")` in `config()`
  • Typed attrs with `email` / `url` / suitable types get appropriate `validatesFormatOf` (design call — may be out of scope)
  • Strengthen the smoke test in `tools/ci/smoke-test-module.sh` to assert `validatesPresenceOf` once this lands
  • Decide whether `wheels generate scaffold` and `wheels generate api-resource` should also emit validations on their generated models (they currently share the same `ModelContent.txt` template)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions