我的应用中有一个评论模型,有很多comment_types
class Comment < ActiveRecord::Base
belongs_to :comment_type, :polymorphic => true
end
我也有一个公共QA系统。所以对于每一对我都有一个模型
class QA < ActiveRecord::Base
has_one :question, :class_name => :comment, :as => :comment_type, :autosave => true
has_one :asnwer, :class_name => :comment, :as => :comment_type, :autosave => true
end
对于我来说,有一个特殊的QA模型表似乎有点过分了。因为这个表应该只有ID键。那么有更好的解决方案吗?或者我的架构可能有问题?
答案 0 :(得分:1)
为什么选择QA模型?我会问一个问题has_many答案和一个问题has_many评论。如果您希望用户能够对其他评论发表评论,您可以选择使用答案has_many评论。我认为容易得多。