Reputation: 6046
I want to implement functionality which let user share posts by other users similar to what Facebook and Google+ share button and twitter retweet.
There are 2 choices:
1) I create duplicate copy of the post and have a column which keeps track of the original post id and makes clear this is a shared post.
2) I have a separate table shared post where I save the post id which is a foreign key to post id in post table.
Talking in terms of programming basically I keep pointer to the original post in a separate table and when need to get post posted by user and also shared ones I do a left join on post and shared post table
Post(post_id(PK), post_content, posted_by)
SharedPost(post_id(FK to Post.post_id), sharing_user, sharedfrom(in case someone shares from non owners profile))
I am in favour of second choice but wanted to know the advice of experts out there?
One thing more posts on my webapp will be more on the lines of facebook size not tweet size.
Upvotes: 0
Views: 222
Reputation: 134
I would suggest that your system would do one of the two: Put code inline for the post (similar to a hyperlink) that would reference the original post. I do not know if you are trying to pull in images or other media. When you encounter this inline code, your system could either create a hyperlink to view the original or pull data from the original into the post that is sharing it.
Alternatively your posts
table could have a column for shared_post
that could either be a post_id
or a hyperlink to an external item to share. Your system can then recognize that if the value is null
or -1
that it is not a shared post and can treat it normally.
I would not recommend creating a new table for storing duplicates of the shared posts. It becomes harder to maintain and update.
Additionally, if you plan on having sharing groups involved in this system, you will most likely need another table that links post_id
to sharing_group_id
.
Upvotes: 1