Search code examples
ruby-on-railshas-manybelongs-to

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?


Solution

  • 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.