Enums
An enum maps a column's stored value to a set of symbolic names. The column holds the backing value (an integer or a string); the model works in terms of the names.
Declaring
Declare an enum in the model's submethod BUILD, alongside attributes,
validations, and associations. The first argument is the column; the second
maps each symbolic name to its backing value.
1 2 3 4 5 6 7 8 | |
Backing values may be integers or strings, and the integers need not be contiguous. A column with no enum keeps its raw value.
Reading and writing
The reader returns the symbolic name; the column stores the backing value:
1 2 3 | |
Assigning either a name or a backing value normalises to the name in memory:
1 | |
Predicates and the bang setter
Each value gets a predicate and a setter. The predicate is-<value> reports
whether that value is current. The setter <value>-bang assigns the value and
saves the record.
1 2 3 4 | |
The bang suffix replaces Rails' status! (Raku method names cannot end in !).
Class scopes
Each value adds a class scope returning a relation filtered to that value:
1 2 3 | |
Inspecting
enum-values('status') lists the symbolic names declared for a column.
1 | |
State machines
There is no built-in state-machine DSL — it is out of scope for the ORM core. Model a state column with an enum and guard the transitions with validations and callbacks, or reach for a dedicated state-machine library when you need guards, events, and transition callbacks as first-class concepts.