Polymorphic cubes
In programming languages, polymorphism usually means the use of a single symbol to represent multiple different types. It can be quite common for a database and application to be designed in such a way that leverages a single database table for entities of different types that share common traits. For example, you are working on an online education platform, where teachers assign lessons to students. The database can contain only two tables: one forusers and another one for lessons. The users table can contain a type
column, with possible values teacher or student. Here is how it could look:
| id | type | name | school |
|---|---|---|---|
| 1 | student | Carl Anderson | Balboa High School |
| 2 | student | Luke Skywalker | Balboa High School |
| 31 | teacher | John Doe | Balboa High School |
lessons table
has both teacher_id and student_id, which are actually references to the
user id. The lessons table can look like this:
| id | teacher_id | student_id | name |
|---|---|---|---|
| 100 | 31 | 1 | Multiplication and the meaning of the Factors |
| 101 | 31 | 2 | Division as an Unknown Factor Problem |
extends feature and
prevents you from duplicating code, while preserving the correct domain logic.
Learn more about using extends here.
The first step is to create a user cube, which will act as a base cube for our
teachers and students cubes and will contain all common measures and
dimensions:
teachers and students cubes from users:
lessons cube: