SQL Table design for users who can leave feedback to users

Viewed 844

I am designing a website where users can post certain things, and other users can bid on it. So after everything is settled, they can leave review to each other for that lets call it "job". In table feedback I think I need to have 2 Userids, one of the person who left feedback and one of the person who received feedback. When a user leaves a review, it makes more sense to create FK on UserId of receiver, because those feedbacks will be viewed on receiver profile page.

Or maybe I got completely wrong approach on this?

enter image description here

1 Answers

In table feedback I think I need to have 2 Userids, one of the person who leave feedback and one of person who received feedback

A feedback is related to two users: a sender (that leaves the feedback) and a receiver. To represent that relationship, you would need to have two foreign keys in the Feedbacks table that reference the Users table. That way, you can enforce integrity across tables (and ensure that every sender and receiver is a valid user). Each feedback is also related to a product, but it seems like you already have that relationship in mind.

So:

Feedbacks
    ReceiverId        foreign key to Users(UserId)
    SenderId          foreign key to Users(UserId)
    ProductId         foreign key to Products(ProductId) 
    ...
Related