I am using a web application like Twitter. I need to implement the retweet action, and one tweet can be rephrased by one person several times .
I have a basic table of tweets that has columns for:
Tweets: tweet_id | tweet_text | tweet_date_created | tweet_user_id
(where tweet_id
is the primary key for tweets, tweet_text
contains the tweet text, tweet_date_created
is the DateTime when the tweet was created, and tweet_user_id
is the foreign key in the users
table and identifies the user who created the tweet)
Now I am wondering how can I implement the retweet action in my database.
Option 1
Should I create a new connection table that looks like this:
Retweets : tweet_id | user_id | retweet_date_retweeted
(Where tweet_id
is the foreign key in the tweets
table, user_id
is the foreign key in the users
table and identifies the user who renamed the tweet, retweet_date_retweeted
is a DateTime that indicates when the retweet was done.)
pros: There will be no empty columns when the user reteet process is created, a new row in the retweets
table.
minus . The request process will be more complicated, it will need to join the two tables and somehow sort the tweets by two dates (when the tweet is not redirected, sort it by tweet_date_created, when the tweet is mixed up, collect it by retweet_date_retweeted).
Option 2
Or should I implement it in the tweets
table as parent_id
, then it will look like this:
Tweets: tweet_id | tweet_text | tweet_date_created | tweet_user_id | parent_id
(where all columns remain unchanged, and parent_id
is the foreign key in the same tweets
table. When the tweet is created, parent_id
remains empty. When the tweet is re-read, parent_id
contains the id of the start of the tweet, tweet_user_id
contains the user who processed the retweets, tweet_date_created
contains DateTime, when a retviant was executed, and tweet_text
remains empty - becouse we do not allow users to change the original tweets when relaying .)
Pros: The query process is much more elegant since I donβt need to join two tables.
cons: There will be empty cells every time a tweet is reread. Therefore, if there are 1,000 tweets in my database and each of them is reviewed 5 times, tweets
will be 5,000 rows in my tweets
table.
What is the most effective way? Is it better to have empty cells or make the query process cleaner?