Designing a database, there's a relationship between two tables, Job
and Document
. One Job
can have multiple Documents
, but one (and only one) of these Documents
needs to be flagged as IsCurrent
. This is not always the most recent Document
associated with that Job
.
Structurally, I can see two ways of doing this.
The first is to add a DocumentId
column to Job
, and a JobId
column to Document
. This will work, but creates a circular reference: when imported into Entity Framework you end up with the peculiar situation that a Job
has both a Document
and a Documents
collection. Likewise that Document
has both a Job
and a Jobs
collection.
The second is to add an IsCurrent
bit flag to the Document
table. This will work, but leaves it logically possible for a Job to have multiple IsCurrent
Documents
, which is not allowed.
Questions:
1) Am I right in thinking there's no "third way" out of this dilemma?
2) Presuming not, which is better, and why? I favour the second solution as it seems much cleaner and we can enforce the single IsCurrent
through the business logic. My colleague favours the former solution because it results in simpler C# code and object references - if we rename the foreign keys, it should avoid the confusion created by Job/Jobs
.