Using Type Tables
Type Tables are two column tables (id and name) which are essentially built into
an enumerated type by Qcodo. So while only some database vendors (e.g. MySQL) offers support for
a formal ENUM column type, Qcodo provides support for the enumerated column types for
all
database vendors through the use of
Type Tables.
Similar to
Association Tables, the code generator will look for a user-defined suffix
(the default is "_type") to mark certain tables as
Type Tables.
Type Tables can
only have 2 columns, a primary key ID and a unique name.
A
Type object will be generated from the table, but note that this
Type object will
not have the CRUD functionality generated for it. Instead, constants will be defined,
one for each row in the
Type Table.
Because this is supposed to be an enumerated data type of some kind, the idea is that rows
should
not be added by the application, but instead, added by developers. So whenever
a new enumerated value needs to be added to this
Type object, you should manually do the SQL INSERT
into this
Type Table, and then re-code generate.
In our example below, we show the contents of
ProjectStatusType. Note how the
Project
class has a relationship with
ProjectStatusType, and how we can display a
Project
object's status using the static methods of
ProjectStatusType.
List All the Project Status Types (Name and Token Value)
Open - Open
Cancelled - Cancelled (This means that the project would be cancelled)
Completed - Completed
Load a Project Object and View Its Project Status
Project ID: 3
Project Name: xx
Project Status: Open