Using Type Tables

Type Tables are essentially built-in enumerated types for QCubed. So while only some database vendors (e.g. MySQL) offer support for a formal ENUM column type, QCubed 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 must have at least 2 columns, a primary key ID and a unique name (named "id" and "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.

You can, if you want, have more than two columns in a type table; QCubed will auto-generate methods based on the names of the columns you defined. In the example below, the Project Status Types table has the following columns: "id", "name" (unique), "description", and "guidelines". QCubed code generator will create methods such as ProjectStatusType::ToDescription() and ProjectStatusType::ToGuidelines() for you.

List All the Project Status Types (Names and Descriptions)

Open - The project is currently active
Cancelled - The project has been canned (sad!)
Completed - The project has been completed successfully

Load a Project Object and View Its Project Status

Project ID: 3
Project Name: Blueman Industrial Site Architecture
Project Status: Open