Using Type Tables

Use Type Tables to create enumerated constant types for QCubed. While only some database vendors (e.g. MySQL) offer support for ENUM or SET column types, QCubed provides support for these enumerated column types for all database vendors through Type Tables.

To tell QCubed that it should treat a particular SQL table as a Type Tables, add a "_type" suffix to the end of the name of the table. Type Tables must have at least 2 columns: a primary key ID named "id", and a unique VARCHAR column "name". Before running the code generator, add data to your type table to define the constants you want generated.

The code generator will create a Type object for the table. Since a Type object should not change during application execution, this object will not have the CRUD functionality but instead will contain constants, one for each row in the Type Table. Whenever a new enumerated value needs to be added to the Type object, you will need to manually do the SQL INSERT into this Type Table, and then run the code generator.

In our example here, 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 generate additional methods based on the names of the additional columns you define. In the example here, the Project Status Types table has the following columns: "id", "name" (unique), "description", and "guidelines". The QCubed code generator will create methods such as ProjectStatusType::toDescription() and ProjectStatusType::toGuidelines() for you.

You can also use an association table with a type table to create a many-to-many relationship with a type. This is similar to the SET type in MySQL, but is database independent.

If you do want to use a "_type" suffix for some reason, you can specify a different suffix in the codegen_settings.xml file in the configuration directory.

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

List the Employees and Their Options

John Doe: Manager, Inactive
Kendall Public: Company Car, Works From Home
Ben Robinson: Contractor, Manager, Inactive
Mike Ho:
Alex Smith: Works From Home
Wendy Smith:
Karen Wolfe: Manager, Company Car
Samantha Jones:
Linda Brady: Inactive
Jennifer Smith: Contractor
Brett Carlisle:
Jacob Pratt:
5 8:
5 8:
5 8:
57417 87887: