Consider a simple situation in which there are 2 tables, named Users and WorkGroups.
- A User's email address is the primary key in the users table.
- A Workgroup_id is the primary key in the WorkGroup table.
- A user can create multiple workgroups.
- A user can be part of just 1 workgroup.
Under this given scenario I need to track which user created a workgroup.
What I have already done:
- Have a variable named workgroup_id in the users table to know which workgroup the user belongs to. This is a foreign key to the workgroup_id in the Workgroup table.
- Have a variable named user_email in the workgroup table to track which user created the workgroup. This is a foreign key to the user_email in the users table.
The problem which I am facing here is that this results in a cyclic reference between the users and the workgroups table. Since cyclic references anywhere in programming are a big no no.
How do I solve this? Is there a better design pattern which I am missing here?
EDIT: As for whether the "circular references are a big no no" or not, conceptually they may not be but since there implementation is non universal in different databases, they still remain a valid problem. This is aggravated by the case when you have use an ORM, where the ORM support for your database limits the kind of database design you can have.