March 2020
Intermediate to advanced
534 pages
14h 15m
English
It is very common to use an enum to define the status of a record, and we will cover state machines in Chapter 15, State Machines. When defining an enum for status, we order the elements so that we can compare them in code.
Given that standard enums are essentially a symbol representing an integer, we can use relative comparisons. These are commonly used in status fields. Let's look at the following vehicle status:
| Symbol | Value |
| Created | 0 |
| Review | 1 |
| Active | 2 |
| Removed | 3 |
If we want all vehicles not removed from service, we could write the following:
select * from vehicles where vehicles.VehicleStatus < VehicleStatus::Removed;
If we want a list of vehicles that have ever been active (for example, ...
Read now
Unlock full access