Question: I am making a webapp right now and I am trying to get my head around the database design.

I have a user model(username (which is primary key), password, email, website)
I have a entry model(id, title, content, comments, commentCount)

A user can only comment on an entry once. What is the best and most efficient way to go about doing this?

At the moment, I am thinking of another table that has username (from user model) and entry id (from entry model)

```
   **username    id**
    Sonic        4
    Sonic        5
    Knuckles     2
    Sonic        6
    Amy          15
    Sonic        20
    Knuckles     5
    Amy          4

```

So then to list comments for entry 4 it searches for id=4.

**On a side note:**
Instead of storing a commentCount, would it be better to calculate the comment count from the database each time when needed?

Answer: 
1. I wouldn't use the username as a primary ID. I would make a numeric id with autoincrement
2. I would use that new id in the relations table with a unique key on the 2 fields
Even though it isn't in the question, you may want to have a userid that is the primary key, otherwise it will be difficult if the user is allowed to change their username, or make certain people know you cannot change your username.

Make the joined table have a unique constraint on the userid and entryid. That way the database forces that there is only one comment/entry/user.

It would help if you specified a database, btw.