This is somewhat a continuation of Database Modeling: Facebook like messages.
I’m trying to model something similar to Facebook messages. In Facebook, users can place comments on walls, on posted medias (e.g. photos, videos), or email each other. The table below tries to represent that:
===========================
message
===========================
- message_id (PK)
- parent_message_id (FK)
- profile_id (FK, referring to who posted the message)
- message
- subject (applicable only for emails)
- timestamp
===========================
wall_message
===========================
- message_id (FK)
- profile_id (FK, referring to who received the message/owner of wall)
===========================
media_message
===========================
- message_id (FK)
- media_id (FK, referring to the specific photo, video, etc.)
===========================
email_message
===========================
- message_id (FK)
- profile_id (FK, referring to who received the message)
A few questions:
- Does anyone see any potential problems with the design?
- How should I handle emails that are sent to multiple recipients?
- How would I query these tables in such a way I can show the most recent, say, 4 messages for a profile owners wall and media (so I can display it on that profile’s wall) order by message timestamp?
Try the following (untested):