Question

I have a question that I hope is quite simple for someone more experienced in database design:

If I have an application, similar to, say a wiki, where there's an author and posts (here called "resources"), I want to show that an author can "have" many posts. So I'm thinking a one-to-many relationship. So I did that.

But then I got to thinking, that not only do I want to represent who authored the post, I also want to be able to tell who modified it. This would then be a relationship between particular fields of the one table to the other, or what? I don't know how this would work. But basically I want to record the authors for each resource, who created it, and who modified it.

Here's the simple model so far:

enter image description here

UPDATE:

I experimented some more, and not really knowing if this is correct, the best way I could figure to achieve this was to create two one-to-many relationships, where I renamed the foreign key created (automatically in MySql Workbench, that is) to created_by and modified_by, respectively...

Am I on the right track or is this not the right way to do it? (In this example I renamed author to user, but that is unimportant)

enter image description here

Was it helpful?

Solution

Based on our communication through comments...

It looks like you simply need two foreign keys (one for "created by" and the other for "modified by" user), like you have shown in your edit to the question.

OTHER TIPS

Your created_by and modified_by should relate back to your author table based on the id columns. In a normalized structure I would not store the names of the authors in the resource table; just the author id's.

I think you would build a relationship to a non-editable WIKI_ENTRY_HISTORY table for the wiki entry, which would store, in chronological order, the history of the specific Wiki page. As well, it would have a HISTORY_CODE (or whatever name you'd give it), that would contain a numerical CODE that informed the DBA of the type of event that occurred (roll-back, creation, etc.) The CODE would link on a 1:1 basis to WIKI_CODE_INFO, which would contain the text translation for the WIKI_CODE (i.e. WIKI_CODE = 1 == WIKI_CODE_INFO = 'created').

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top