【问题标题】:what relation use for retweet functionality?什么关系用于转发功能?
【发布时间】:2012-02-05 15:54:10
【问题描述】:

我正在关注这个教程http://ruby.railstutorial.org/ruby-on-rails-tutorial-book

我的问题是,用户可以使用转发功能是什么关系?

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

如果用户想要转发,这种关系是否有效? 或者如果同一条推文属于多个用户,我是否必须使用 has_and_belongs_to_many?

【问题讨论】:

    标签: ruby-on-rails has-many belongs-to


    【解决方案1】:

    在 Twitter 上,模型似乎是一条推文一个用户创建,但属于(显示在时间轴上)许多用户。也就是说,一条推文和用户之间存在两个关系。 belongs to 关系中不是 用户创建的用户是转发推文的用户。

    【讨论】:

    • 你能举个例子模型关系吗?谢谢
    • @hyperrjas 抱歉,我没有方便的 Rails 暂存器项目来测试代码,这只是关于模型设计的答案。也许等一下,看看其他人是否会做出更彻底的回答。
    猜你喜欢
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-24
    • 2010-10-22
    • 2019-04-16
    • 2011-10-18
    • 1970-01-01
    相关资源
    最近更新 更多