Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what relation use for retweet functionality?

I'm following this tutorial http://ruby.railstutorial.org/ruby-on-rails-tutorial-book

My question is, what is the relation for user can use retweet function?

e.j.

class Micropost < ActiveRecord::Base
  attr_accessible :content

  belongs_to :user
end

class User < ActiveRecord::Base
  attr_accessor :password
  attr_accessible :name, :email, :password, :password_confirmation

  has_many :microposts
  .
  .
  .
end

If a user want make a retweet, this relation is valid? or would must I use has_and_belongs_to_many?. if the same tweet belongs_to many user?

like image 443
hyperrjas Avatar asked Apr 12 '26 01:04

hyperrjas


1 Answers

On Twitter, the model seems to be that one tweet is created by one user, but belongs to (is shown on the timelines of) many users. That is, there are two relations between a tweet and user. The users in the belongs to relation that aren't the created by user are the ones retweeting the tweet.

like image 61
millimoose Avatar answered Apr 13 '26 21:04

millimoose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!