GenRocket Parent/Child/Sibling Relationships Concepts
GenRocket Parent/Child/Sibling Relationships Concepts govern the way complex Domain models can be easily represented and manipulated with full referential integrity.
For this example, the following Entity Relationship Diagram will be used.
This diagram describes a common, normalized database model of a user entity having foreign key relationships to three other entities: department, role, and security_level. In a database, these three entities are seen as Parents to the user entity.
Let’s also assume that there are three roles: Manager (MGR), Supervisor (SPV), and Employee (EMP). Additionally, there are 5 Security Levels: L1, L2, L3, L4, and L5.
If we want to generate only 100 users for a single department, traversing all three entities as a parent to the user entity, makes generating only 100 rows of user test data virtually impossible.
Why? Because of the number of permutations necessary to produce all possible parent/child combinations of user test data.
For 1 department, 3 roles, and 5 security levels, we would need 1,500 permutations to satisfy all possible combinations for just 100 users.
For 10 departments with 3 roles and 5 security levels, our permutations jump from 1,500 users to 15,000 users.
If we want 10 departments each to have 1000 users, our permutations jump from 15,000 users to 150,000 users.
And if we change the number of roles to 5 and the number of security levels to 10, our permutations would jump from 150,000 users to 500,000 users.
How then can we generate only 100 users for one department and manage to produce all possible roles and security levels within the set of 100 users?
By following one simple rule! In GenRocket, an entity may have only one parent, but can have many siblings.
Since role and security_level are adjectives that hep describe the user, department should be the parent of user. Role and security_level should be siblings to the user.
Having only one parent and many siblings, GenRocket will produce the user test data in the following manner:
- First, it will generate data for one department, because department is the parent of user.
- Before each of the 100 users is generated, one row from each of the siblings is generated.
- And now that the user has full referential integrity from its parent and sibling relationships, the user test data can be generated.
This process will repeat itself until all 100 users are generated, yielding all unique combinations of roles and security levels, guaranteeing full referential integrity.