Question

I am designing a database for a social media website (uni assignment). I have been struggling with the messages link to member. There will be a need for two foreign keys from the same primary key in messages. One for the sending member and one for the receiving member. I was unsure if this was possible or a good idea so i was thinking of assign a member to a inbox (Many Members - One Inbox). Then assign all messages to the inbox (One Inbox - Many Messages).


Member Many------1 Inbox 1------Many Messages

Tables look like....

##################

Member Profiles
Member ID (PK)
Name
Gender
Inbox ID (FK)

##################

Inbox
Inbox ID

##################

Message
Message ID (PK)
Inbox ID (FK)
Message Direction .... either to or from (then the members name)
Member ID (FK)

That's what Ive got so far id appreciate some pointers if ive gone off the right path. Because the more i look at my design the less i like it.

Was it helpful?

Solution 2

No don't do that

Messages can belong to multiple members and members can have mulitple messages, so you need what is called a Join table.

MemberMessage
Memberid
Message id

OTHER TIPS

The draft model may helps you:

Message creation:
enter image description here
Message consumption: (after send message process) enter image description here

Have you considered changing the MemberID field on the Message table to something like SendingMemberID, and then adding another field called ReceivingMemberID? This would allow you to avoid the somewhat confusing Message Direction field.

Sure you'd need to join to it twice to get all incoming and outgoing messages for a user, but that's really not a bad thing. The alternative option of having two records for each message (one for sender, one for receiver) has its own drawbacks.

Good luck!

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